<a ng-click="vm.getComment(post);isCollapsed{{post._id}} = !isCollapsed{{post._id}}">
我已经写了上面的代码,用于显示每个折叠的多个 点击显示特定列表并发现belove错误可以告诉我上面的行是否正确
angular.js:13920错误:[$ parse:syntax] http://errors.angularjs.org/1.5.8/ $ parse / syntax?p0 =%7B&amp; p1 = is%20an%20unexpected%20token&amp; p2 = 32&amp; p3 = vm.getComment (POST)%3BisCollapsed%7B%7Bpost._id%7D%7D%20%3D%20%isCollapsed 7B%7Bpost._id%7D%7D&安培;!P4 =%7B%7Bpost._id%7D%7D%20%3D %20!isCollapsed%7B%7Bpost._id%7D%7D 在http://localhost:6161/lib/angular/angular.min.js:6:412 在s.throwError 在kc.parse(http://localhost:6161/lib/angular/angular.min.js:276:122) at oa(http://localhost:6161/lib/angular/angular.min.js:71:38) 在s(http://localhost:6161/lib/angular/angular.min.js:59:121) 在s(http://localhost:6161/lib/angular/angular.min.js:59:253)
答案 0 :(得分:1)
您不能将作用域变量连接为字符串,并希望变成具有该名称的变量。我建议使用对象或/和数组来存储有关帖子的信息,只需切换每个对象的布尔值。这是一个快速演示:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.ids = [10, 21, 34, 100];
$scope.isCollapsed = {
"10": false,
"21": false,
"34": false,
"100": false
};
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="id in ids">
<button ng-click="isCollapsed[id] = !isCollapsed[id]">
Hide {{id}}
</button> <br>
{{isCollapsed[id]}}
<hr>
</div>
</div>
&#13;