这是我使用rootProvider模板的代码
<ul >
<li ng-repeat="obj in myArray">{{obj.com_name}}</li>
</ul>
我的控制器是:
routingApp.controller('Controller-Param', function($scope, $routeParams, $http) {
var aid = $routeParams.id;
$scope.myArray = "[{"company_id":"1","com_name":"jcb","val_equ_id":"1","created_on":"2018-03-24 13:00:43"},{"company_id":"2","com_name":"komatsu","val_equ_id":"1","created_on":"2018-03-24 13:00:43"}]
";
});
这是评论脚本
<div ng-view=""><ul class="ng-scope">
<!-- ngRepeat: obj in myArray -->
</ul>
答案 0 :(得分:4)
您需要删除JSON数组周围的引号“”。否则它将被视为一个字符串,所以你看到一个空div
<强>样本强>
var routingApp = angular.module('myApp',[]);
routingApp.controller('Controller-Param', function($scope) {
$scope.myArray = [{"company_id":"1","com_name":"jcb","val_equ_id":"1","created_on":"2018-03-24 13:00:43"},{"company_id":"2","com_name":"komatsu","val_equ_id":"1","created_on":"2018-03-24 13:00:43"}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp" ng-controller="Controller-Param">
<ul >
<li ng-repeat="obj in myArray">{{obj.com_name}}</li>
</ul>
</body>
答案 1 :(得分:0)
$scope.myArray = [{"company_id":"1","com_name":"jcb","val_equ_id":"1","created_on":"2018-03-24 13:00:43"},{"company_id":"2","com_name":"komatsu","val_equ_id":"1","created_on":"2018-03-24 13:00:43"}];
在代码中替换此行