angularJs ng-repeat不显示工厂阵列

时间:2015-08-27 09:22:50

标签: angularjs angularjs-ng-repeat factory

我遇到了ng-repeat问题。

我有2个表,其中一个表显示数据。你可以点击每个元素和 第二个表显示有关所选行的更多信息。

第二个表的ng-repeat仅循环一次,即使我有两个要显示的对象。

这是测试代码:

<!DOCTYPE html>
<html>
    <head>
        <title>ng-repeat doesn't work</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    </head>
<body>
    <script>
         appTest=angular.module('testApp',[])
         .factory('adminClientService',function()
            {
                var cliente=[];

                var addCliente=function(newClient)
                {
                    cliente.pop(); //delete element of array
                    cliente.push(newClient); //add element on array

                };

                var getCliente=function(){
                    return cliente;
                };

                var clearClientList=function()
                {
                    cliente=[];
                };

                return{ addCliente:addCliente,
                        getCliente:getCliente,
                        clearClientList:clearClientList};
            })
            .controller('adminShowUserDataPanel',['$scope','adminClientService',function($scope,adminClientService){
                           this.cliente=adminClientService.getCliente();
            }])             
            .controller('adminUserPanel',['$scope','adminClientService',function($scope,adminClientService)
            {
                this.clientList=[
                    {
                        name:'a',
                        value:1,
                        otherVal:[{subName:'aa'}]
                    },
                    {
                        name:'b',
                        value:2,
                        otherVal:[{subName:'bb'},{subName:'bbBB'}]
                    },
                    {
                        name:'c',
                        value:3,
                        otherVal:[{subName:'cc'},{subName:'cCcC'}]
                    },
                    ];

               this.selectedClient=function(data)
               {
                   adminClientService.addCliente(data.otherVal);
               };


            }]);

    </script>
    <div ng-app="testApp">
        <div id='table1'>
            <table class="table table-stripped table-hover" ng-controller="adminUserPanel as panel">
                <thead>
                        <tr><th class="text-center">#1</th><th class="text-center">#2</th></tr>
                </thead>
                <tbody>
                    <tr ng-repeat="data in panel.clientList" ng-click="panel.selectedClient(data);">
                        <td class="text-center">{{data.name}}</td>
                        <td  class="text-center">{{data.value}}</td>
                    </tr>
                </tbody>
                <tfoot>
                </tfoot>
            </table>
        </div>

        <div id='table2'>
            <table class="table table-stripped table-hover" ng-controller='adminShowUserDataPanel as showSubData'>
                <thead>
                    <tr><th class="text-center">object have...</th><th class="text-center">data</th><th class="text-center">Len.</th></tr>
                </thead>
                <tbody>
                    <tr ng-repeat="client in showSubData.cliente">
                        <td class="text-center">{{client}}</td>
                        <td class="text-center">{{client[$index].subName}}</td>
                        <td class="text-center">long:{{client.length}}</td>
                    </tr>
                </tbody>
                <tfoot>
                </tfoot>
            </table>
        </div>
    </div>
</body>

我已经阅读过$ apply等,但它没有用(也许我没有正确使用它)

我正在学习Angular,对我来说有点困惑的是,它在第​​一个表中有效,但在第二个表中却没有

0 个答案:

没有答案