2016-10-21 22 views
2

我有以下從localStorage的結果,角JS,檢查子以逗號分隔字符串中的角JS

HD, TA, DI 

現在在角JS我想在此基礎上,以顯示潛水, 意味着當我的高清我只想顯示送貨上門按鈕, 如果我有HD,TA我要顯示送貨上門以及帶走Butttons 如果我有HD,TA,DI然後我想要顯示送貨上門,帶走和用餐鈕釦。

<div ng-if="result==What should be here"></div> 

回答

1

您可以直接使用NG-IF($scope.items='HD, TA, DI'

<button ng-if="items.indexOf('HD')>=0">HD</button> 
    <button ng-if="items.indexOf('TA')>=0">TA</button> 
    <button ng-if="items.indexOf('DI')>=0">DI</button> 

http://plnkr.co/edit/lCtywXHZh9474MviIoTZ?p=preview

0

在你的控制器:

app.controller('MainCtrl', function($scope) { 
    $scope.localStorage = ["HD", "TA", "DI"]; 
    if ($scope.localStorage.indexOf("HD") >= 0) { 
    $scope.hd = true; 
    } 
    if ($scope.localStorage.indexOf("TA") >= 0) { 
    $scope.ta = true; 
    } 
    if ($scope.localStorage.indexOf("DI") >= 0) { 
    $scope.di = true; 
    } 
}); 

而在你的看法:

<html ng-app="myApp"> 
     <body ng-controller="MainCtrl"> 
     <div ng-if="hd">HD</div> 
     <div ng-if="ta">TA</div> 
     <div ng-if="di">DI</div> 
     </body> 
</html> 
相關問題