data-ng-repeat在这里不能很好地工作

时间:2013-09-11 09:30:55

标签: angularjs

我的代码出了什么问题?它必须显示所有NAME,但它不能很好地运行

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script>
    DemoApp = angular.module("DemoApp", []);
    DemoApp.controller('SimpleController', function ($scope) {
        $scope.Customer = [{ Fname: 'Alireza', City: 'Tehran' }, { Fname: 'Ali', City: 'Tabriz' }, { Fname: 'Ehsan', City: 'Abadan'}];
    });
    DemoApp.controller();
</script>
</head>
<body data-ng-app="DemoApp"> 
<div data-ng-controller="SimpleController">
<ul>
    <li data-ng-repeat="cust in Customer">{{cust.Fname}}</li>
</ul>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

大写不匹配Fname!= FName

http://jsfiddle.net/cdCqu/

HTML

<body data-ng-app="DemoApp"> 
<div data-ng-controller="SimpleController">
<ul>
    <li data-ng-repeat="cust in Customer">{{cust.Fname}}</li>
</ul>
</div>
</body>

JS

angular.module("DemoApp", []).controller('SimpleController', function ($scope) {
        $scope.Customer = [{ Fname: 'Alireza', City: 'Tehran' }, { Fname: 'Ali', City: 'Tabriz' }, { Fname: 'Ehsan', City: 'Abadan'}];
    });

答案 1 :(得分:1)

试试这个jsFiddle,你也不需要数据属性以及FName必须是Fname,你不需要附加带有ng属性的数据

just remove data attribute 

http://jsfiddle.net/imsaurabh/K6qwQ/