1

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
  • 1
    Have you looked and ng-init? Commented Apr 13, 2013 at 16:19

1 Answer 1

8
{{card=foo;""}}

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.