Is concatenation possible in the ng model?

Just a question: is it possible to combine a string with the name "id" inside the ng-model into the variable product.id in angularjs? Is there a way this approach could work?

It works:

ng-model="currentQuantity['id1']"

This does not work:

ng-model='currentQuantity[id + "" + product.id]'
+4
source share
2 answers

You need to specify a string idor it will be evaluated as an area variable

Edit:

ng-model='currentQuantity[id + "" + product.id]'

to

ng-model='currentQuantity["id" + product.id]'
+3
source

One possible way to solve the problem would be to use a two-dimensional variable to represent yours ng-model, i.e.

ng-model='currentQuantity[id][product.id]'
+3
source

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


All Articles