代码之家  ›  专栏  ›  技术社区  ›  zb22

带表格的角度指令

  •  0
  • zb22  · 技术社区  · 9 年前

    我试图在表格中使用角度指令,但我没有看到任何数据, 我也在使用bootstrap来设计桌子的样式。

    希望您能提供帮助,以下是我代码的主要部分:

      <table class="table">
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Username</th>
            </tr>
        </thead>
        <tbody ng-repeat="m in users">
    
            <my-dir my-obj="m"></my-dir>
    
        </tbody>
    </table>
    

    var myApp = angular.module('myApp', ['ngRoute'])
    
    myApp.config(function($routeProvider) {
    
        $routeProvider
            .when('/', {
            templateUrl: 'pages/main.html',
            controller: 'AppCtrl'
        })
     
    
    });
    
    myApp.controller('AppCtrl', function($scope) {
        
    
        $scope.users = [{name: 'john', age: 16}, {name: 'dani', age: 10}];
        
        
        
    });
    
    myApp.directive('myDir', function(){
        return{
            templateUrl: 'directive/mytbl.html',
            replace: false,
            scope:{
                myObj: '='
            }
        }
    })

    mytbl.html:

    <td>{{ myObj.name }}</td>
    <td>{{ myObj.age }}</td>
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   Brian    9 年前

    您正在创建 <tbody>

    尝试更改为:

    <tbody>
       <tr ng-repeat="m in users" my-dir my-obj="m"></tr>
    </tbody>
    

    推荐文章