How to concatenate string inside html document

扶醉桌前 提交于 2021-02-07 13:11:36

问题


How can I concatenate string in HTML Attribute. I am using angular controller and in the part where I write some array in HTML (Code is below), I want to give input tag name that is "kolicina" + {{idhrana}} witch is attribute of object jelo.

 <div class = "rezultat" ng-repeat="jelo in hrana | filter:pretrazi_namirnice">
     <div>  {{jelo.naziv}}  </div>
     <div>  {{jelo.energijaKCal}}</div>
     <div>  {{jelo.proteini}}</div>
     <div>  {{jelo.uglj_hidrati}}</div>
     <div>  {{jelo.masti}}</div>
     <div><input type=text nama="kolicina"+{{idhrana}}></div>
     <div><input  type="button"  ng-click = 'dodaj(jelo)' value="Dodaj"></div>
 </div>

回答1:


You can do it like so:

<input type=text name="kolicina{{idhrana}}"></div>

No need to explicitely concatenate it. Also, I think you had a typo with nama versus the name-attribute.




回答2:


http://plnkr.co/edit/uJcDZkrGNqzSibpgkTc9?p=preview

<input type=text name="kolicina {{idhrana}}">

working plnkr for understanding. hope this will help you.



来源:https://stackoverflow.com/questions/44215037/how-to-concatenate-string-inside-html-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!