3

I have got following result from localstorage,

HD, TA, DI

Now In angular js I want to display divs based on this data as:

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>

2 Answers 2

3

You can use directly in 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

Sign up to request clarification or add additional context in comments.

Comments

1

In your controller:

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;
  }
});

And in your view:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.