我在 angularJS 上工作,我的代码很好,但我被困在一个地方,我无法找到为什么 ng-class-even
中需要额外引号的原因指令。
在这一行<tr ng-repeat="x in records" ng-class-even='"striped"'>
为什么striped会这样写"'striped'"
而不是这个 "striped"
.striped {
color:white;
background-color:black;
}
<body ng-app="myApp">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<table ng-controller="myCtrl">
<tr ng-repeat="x in records" ng-class-even="'striped'">
<td>{{x.Name}}</td>
<td>{{x.Country}}</td>
</tr>
</table>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.records = [
{
"Name" : "Alfreds Futterkiste",
"Country" : "Germany"
},
{
"Name" : "Berglunds snabbköp",
"Country" : "Sweden"
},
{
"Name" : "Centro comercial Moctezuma",
"Country" : "Mexico"
},
{
"Name" : "Ernst Handel",
"Country" : "Austria"
}
]
});
</script>
</body>
最佳答案
ng-class-even
expects anexpression
but you are willing to assign a hard coded string and strings are wrapped inquotes
to be validtoken
or elseangular
parser will look formodel-name
having name asstriped
关于javascript - 为什么 ng-class-even 需要额外的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37718424/