2016-05-18 9 views
0

Ich habe $rootScope._ = window._; in app.run and $scope._ = _; in Controller eingestellt. Wenn ich jedoch versuche, über _.includes zu evaluieren, werden die darin enthaltenen Variablen gut ausgewertet (das kann ich durch Inspizieren des Elements sehen), aber ng-disable evaluiert keinen booleschen Wert.lodash _.includes nicht zu wahr oder falsch in der Winkelansicht zu bewerten

<li data-ng-repeat="acLink in accordion.links"> 
    href="#/{{acLink.domain}}/{{acLink.id}}" uib-tooltip="{{acLink.title}}" ng-disabled="_.includes({{allowedRoles}},{{acLink.role_d}})" style="color:#4d4d4d">{{acLink.title}}</a> 
</li> 

<a href="#/abc/home" uib-tooltip="CBOE Home" ng-disabled="_.includes(["abc", "xyz"],'abc')" style="color:#4d4d4d" class="ng-binding" aria-disabled="false"> Home</a> 

Ich erhalte die folgende Fehlermeldung:

angular.min.js:103 Error: [$parse:syntax] 
at http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:6:416 
    at hb.throwError (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:190:254) 
    at hb.primary (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:189:477) 
    at hb.unary (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:197:82) 
    at hb.multiplicative (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:196:324) 
    at hb.additive (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:196:182) 
    at hb.relational (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:196:48) 
    at hb.equality (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:195:418) 
    at hb.logicalAND (http://localhost:63342/dashboard_core/vendor/angular/angular.min.js:195:294) <a href="#/{{acLink.domain}}/{{acLink.id}}" uib-tooltip="{{acLink.title}}" ng-disabled="_.includes({{allowedRoles}},{{acLink.role_d}})" style="color:#4d4d4d" class="ng-binding"> 
+0

Besser erstellen Sie eine Funktion anstelle von Inline-JS. – Tushar

Antwort

0

ich den Code-Snippet falsch verstanden. Ich sehe jetzt, dass Sie die Werte generieren, die Sie mithilfe der Interpolation einfügen möchten. In diesem Fall ist Tushars Vorschlag, die Funktion in Ihren Controller-Code zu verschieben, anstatt lodash an die View zu übergeben, eine bessere Option.

// HTML 
ng-disabled="includes(allowedRoles, acLink.role_d)" 

// JS 
$scope.includes = function(list, item) { 
    _.includes(list, item); 
} 
0

sollten Sie hierfür eine separate Funktion erstellen. Beispiel:

$scope.isDisabled = function(){ 
    return _.includes(["abc", "xyz"],'abc'); 
}; 

<a href="#/abc/home" uib-tooltip="CBOE Home" ng-disabled="isDisabled()" style="color:#4d4d4d" class="ng-binding" aria-disabled="false"> Home</a>