How to assign a (dynamic) variable in HTML using angularJS

狂风中的少年 提交于 2019-12-11 13:35:23

问题


I have a complex directive I use though out my application on many HTML pages. It has become complicated and contains nested structures so I copy and paste it everywhere:

<card ng-repeat="card in deck"
    scalex="card.scalex"
    scaley="card.scaley"
    ...

    <img ng-repeat="wait in [] | range:card.f" src="symbol.png"       style="position:absolute; left:{{(13*$index + 3 )}}px; z-index: 1;bottom:0px"></img>
    ...

    <icon ng-repeat="icon in card.icons"
        x="icon.x"
        y="icon.y"
        ...
        />
</card>

However, not always is this directive bound to the variable "card". Thus after copy and pasting I need to change lots of assignments from the form "card.bar" to "foo.bar". This is somewhat labourius and error prone. I would like to assign a bound variable card that has the same state as foo. Then I will not need to change the source I keep copy and pasting.

So is there a one liner I can add infront of a directive, in the HTML, that will reassign foo to card?


回答1:


{{card=foo;""}}

Ahhh the trailing, "" stops the AngularJS expression being evaluated to any text



来源:https://stackoverflow.com/questions/15987949/how-to-assign-a-dynamic-variable-in-html-using-angularjs

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