0

Hi I have a repeat loop in which

<div draggable="true" ng-repeat="item in items>
    <span>{{item.Id}}</span>
    <span>{{item.des}}</div>
</div>

What i want to do is that if item.valid=0 i want to set draggable value to false, else it stays true. I was looking into ng-switch but it didnt work fine. Please let me know how to set draggable value to true or false depending upon the item.valid value. Thanks

J. Davidson
  • 3,297
  • 13
  • 54
  • 102
  • This doesn't make any sense. You want to set the outer element's draggable state based on a repeating value? How do you determine which value overwrites the state? – David L Jan 10 '16 at 23:52
  • Take a look at this http://stackoverflow.com/a/16669790/3951400 – E. Sundin Jan 10 '16 at 23:52
  • What I mean is for each item.valid value if it is 0 draggable should be set to False if item.valid is 1 then draggable should be true. – J. Davidson Jan 10 '16 at 23:55

1 Answers1

0

You can use something like this if you want to set draggable for each item.

<div ng-repeat="item in items">
    <div ng-attr-draggable="{{item.valid == 1 ? 'true' : 'false' }}">
        <span>{{item.Id}}</span>
        <span>{{item.des}}</div>
    </div>
</div>
artm
  • 8,554
  • 3
  • 26
  • 43
  • if i understand OP correctly - he wants it to be true for every thing except 0, not just if it is 1. `{{item.valid > 0 ? 'true' : 'false' }}` is probably what he needs. good answer though, i learned something new ;) – HolyMoly Jan 11 '16 at 00:02
  • @HolyMoly Yeah you might be right. We'll see when OP comments. – artm Jan 11 '16 at 00:04
  • in fact artm, if you could take a peek at the question i just posted, that would be awesome. i'm super stuck :( http://stackoverflow.com/questions/34712042/how-do-i-create-menu-items-that-i-can-swap-out-depending-on-page-login-status – HolyMoly Jan 11 '16 at 00:04
  • @HolyMoly Everything else then 0 is `item.valid !== 0` ;) – E. Sundin Jan 11 '16 at 00:05