我想知道我在使用角度时出错了,因为ngrepeat没有显示数据。
我这里有一个小提琴 http://jsfiddle.net/e0e7dee5/
<div ng-controller="MyCtrl">
<div class="container-fluid">
<div ng-repeat="u in utilities.all">
{{u.name}}
</div>
</div>
</div>
上面应该是对的吗?
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
//var utilities = this;
var utilities = {};
utilities.all = [{ .... }]; // this is my data it is in the fiddle
console.log(utilities.all); // this displays array of objects
}
答案 0 :(得分:1)
您应该将var utilities = {};
更改为$ scope.utilities = {};
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
//var utilities = this;
$scope.utilities = {};
$scope.utilities.all =
[{
"programId": 1062,
"name": "Atlantic City Electric",
"utilityTypeName": "Electric",
"programName": "Test Program 24",
"rate": 0.0775,
"term": 12,
"serviceReference": false,
"accountNumberTypeName": "Account Number",
"accountNumberLength": 10,
"msf": 4.95,
"etf": 100,
"unitOfMeasureName": "KwH",
"meterNumberLength": null,
"zip": "85281",
"$$hashKey": "object:325"
}, {
"programId": 1063,
"name": "Atlantic City Electric",
"utilityTypeName": "Electric",
"programName": "Test Program 12",
"rate": 0.0875,
"term": 24,
"serviceReference": false,
"accountNumberTypeName": "Account Number",
"accountNumberLength": 10,
"msf": 5.95,
"etf": 150,
"unitOfMeasureName": "KwH",
"meterNumberLength": null,
"zip": "85281",
"$$hashKey": "object:326"
}, {
"programId": 1064,
"name": "Atlantic City Electric",
"utilityTypeName": "Gas",
"programName": "Test Gas Program 12",
"rate": 0.555,
"term": 12,
"serviceReference": false,
"accountNumberTypeName": "Account Number",
"accountNumberLength": 10,
"msf": 1,
"etf": 10,
"unitOfMeasureName": "Therm",
"meterNumberLength": 5,
"zip": "85281",
"$$hashKey": "object:333"
}];
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<div class="container-fluid" ng-repeat="u in utilities.all">
<div>
{{u.name}}
</div>
</div>
</div>
&#13;