角度表示骆驼属性始终为假

问题描述:

我有这个代码和角度表示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>

我还试图用dahsboard["is-current-user-owner"]但它不工作,它甚至如果这是真的还是假的。

+1

通过回答后,你会感觉非常糟糕。:) – Rayon

+0

我同意这一点,但我们都在某些时候做对了,对吧? :) –

你有拼写错误的问题变化,dahsboarddashboard

但是,恕我直呼尝试使用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> 

这应该解决您访问模型的问题。这是采用了棱角分明1

https://toddmotto.com/digging-into-angulars-controller-as-syntax/

约翰·帕帕方针https://github.com/johnpapa/angular-styleguide


编辑

(所需6个字符)上所有线正确dahsboard的建议。

+0

我使用“控制器”和角度组件我的代码。 – jcubic

正确dahsboarddashboard,它可能工作。

更正代码:

<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>