我是角度js的新手,我现在正在练习过滤器。我完全能够遍历对象数组但是当我使用对象的对象时,我的浏览器会抛出错误: "未捕获的SyntaxError:意外的令牌"
<!DOCTYPE>
<html>
<head>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="myCont">
<div ng-repeat="b in ar2">
{{b}}
</div>
{{a}}
</br></br>
{{c | myFilt}}
</br>
</br>
<div ng-repeat="(key,value) in d">
{{key.a|myFilt}}
</div>
</div>
</div>
<script src="jquery-3.0.0.js"></script>
<script src="angular.js"></script>
<script src="angular_try.js"></script>
</body>
</html>
这是角度js:
var myApp = angular.module("myApp",[])
myApp.controller("myCont",["$scope","$filter",function($scope,$filter){
$scope.a ="pro";
$scope.arr = ["abc","bcd","cdb"];
$scope.arr3 = [100,200,300];
$scope.ar2=[];
$scope.c = 10;
$scope.d = {{a:"mishtu",b:500,c:"mondal"},{a:"tulu",b:400,c:"mondal"},
{a:"titlu",b:600,"c":"mondal"}}
}])
答案 0 :(得分:0)
对象包含始终在(键,值)对中的值,但对象包含
$scope.d = {{a:"mishtu",b:500,c:"mondal"},{a:"tulu",b:400,c:"mondal"},
{a:"titlu",b:600,"c":"mondal"}}
正在保存对象列表,因此您应该将其声明为数组。 喜欢这个
$scope.d = [{a:"mishtu",b:500,c:"mondal"},{a:"tulu",b:400,c:"mondal"},
{a:"titlu",b:600,"c":"mondal"}]
应该如何使用:
var app = angular.module('myApp', []);
app.controller('MyController', ['$scope', function($scope) {
$scope.title = 'Hello world';
$scope.d = [{
a: "mishtu",
b: 500,
c: "mondal"
}, {
a: "tulu",
b: 400,
c: "mondal"
}, {
a: "titlu",
b: 600,
"c": "mondal"
}];
}]);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller='MyController' ng-app="myApp">
<div>{{title}}</div>
<table border="1" ng-repeat="myObj in d">
<tr ng-repeat="(x, y) in myObj">
<td>{{x}}</td>
<td>{{y}}</td>
</tr>
</table>
</div>
&#13;