我有这个代码,而angular表示dahsboard.isCurrentUserOwner
总是假的,即使它是真的。
angular.module('app', []).controller('main', function($scope) {
$scope.dashboards = [{"id":23,"name":"AFM Dashboard","description":"Dashboard displaying the size of the queue for each of the AFM replicated filesets. If the queue_length is > 0 and is a flat line there may be some issue with the replication of the data.","isCurrentUserOwner":true},{"id":24,"name":"GPFS","description":"GPFS state summary dashboard.","isCurrentUserOwner":false},{"id":25,"name":"test1231","description":"testtesttesttest 234567890-1","isCurrentUserOwner":false},{"id":28,"name":"test","description":"test","isCurrentUserOwner":true}];
$scope.sort = 'asc';
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.js"></script>
<div ng-app="app" ng-controller="main">
<div ng-repeat="dashboard in dashboards">
<div>{{dashboard|json}}</div>
<div>{{dahsboard.isCurrentUserOwner ? 'true' : 'false'}}</div>
<div ng-if="dahsboard.isCurrentUserOwner">
show
</div>
<div ng-if="!dahsboard.isCurrentUserOwner">
not show
</div>
</div>
</div>
&#13;
我也曾尝试使用dahsboard["is-current-user-owner"]
,但它不起作用,即使它是真的,它仍然是假的。
答案 0 :(得分:3)
您的问题更改错误,dahsboard
改为dashboard
。
但恕我直言尝试使用controller as
语法,最好访问控制器内部的模型,将来最好按照指南工作,这将有助于您避免出现大问题作用域。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.js"></script>
<div ng-app="app" ng-controller="main as mainCtrl">
<div ng-repeat="dashboard in mainCtrl.dashboards">
<div>{{dashboard|json}}</div>
<div>{{dashboard.isCurrentUserOwner ? 'true' : 'false'}}</div>
<div ng-if="dashboard.isCurrentUserOwner">
show
</div>
<div ng-if="!dashboard.isCurrentUserOwner">
not show
</div>
</div>
</div>
这可以解决您访问模型的问题。这是使用Angular 1的建议。
https://toddmotto.com/digging-into-angulars-controller-as-syntax/
John Papa GuideLine https://github.com/johnpapa/angular-styleguide
修改强>
(需要6个字符)在所有行上更正dahsboard
。
答案 1 :(得分:1)
使用dahsboard
更正dashboard
,它可能有用。
更正后的代码:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.js"></script>
<div ng-app="app" ng-controller="main">
<div ng-repeat="dashboard in dashboards">
<div>{{dashboard|json}}</div>
<div>{{dashboard.isCurrentUserOwner ? 'true' : 'false'}}</div>
<div ng-if="dashboard.isCurrentUserOwner">
show
</div>
<div ng-if="!dashboard.isCurrentUserOwner">
not show
</div>
</div>
</div>