NgIf with evaluated variable as part of expression

I am trying to do the following:

ng-if="newItem.location == 'belowLesson{{lesson.Id}}'" 

and it only works for ng-show.

In other words, if I set newItem.location to the line "belowLesson28" and the lesson. In this area - 28, I would like it to work. I would prefer not to use ng-show because it is a drag and drop application (I use it several times in ng-repeat).

I will build plunkr, just thought I would put this earlier if this would be an obvious fix in the syntax or something like that.


Here plunkr: http://plnkr.co/edit/UFpTQ6zsvlCWVep5Ai5I?p=preview

+4
source share
1 answer

The first problem in your plunkr is setting the current item. Instead

 <button ng-click="chosenItem = {{item}}"> 

he should be

 <button ng-click="chosenItem = item"> 

The second problem is that ng-if creates its own area, and changing the value directly in the controller area will not change the previously saved (through inheritance) value in the ng-id area. Therefore, you must save the selected item in a sub-object, as shown in the following plunkr: http://plnkr.co/edit/qOoZtnCqPuwvP3fGoUxw?p=preview

+4
source

Source: https://habr.com/ru/post/1498742/


All Articles