2016-05-18 7 views
0

コントローラーに​​を設定しました。 しかし、私が_.includes経由で評価しようとすると、内部の変数はきれいに評価されます(要素を検査することでわかります)が、ng-disabledはブール値に評価されません。lodash _.includesが角度表示でtrueまたはfalseに評価されない

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

私は、次のエラーを取得しています:

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

インラインJSではなく関数を作成してください。 – Tushar

答えて

0

私はコードスニペットを誤解。補間を使用して含める値を生成していることがわかりました。その場合、ビューにロダッシュを渡すのではなく、コントローラコードに関数を移動するというTusharの提案がより良い選択肢です。

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

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

このために別の機能を作成する必要があります。 例:

$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> 
関連する問題