我从localstorage获得了以下结果,
HD, TA, DI
现在在角度js中我想基于这些数据显示div:
HD : Only display Home Delivery Button.
HD, TA : Display Home Delivery and Take Away Buttons.
HD,TA,DI: Display Home Delivery, Take Away, dine In Buttons.
<div ng-if="result==What should be here"></div>
答案 0 :(得分:2)
您可以直接在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>
答案 1 :(得分: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>