0

I'm wondering why templating tag [[ opt.option ]] is not evaluating to a value sometimes in the following code

<span ng-repeat="opt in options">
<button ng-click="button = [[ opt.option ]]" ng-class="{ active : button == [[ opt.option ]] } ng-cloak>
<i class="icon-tick visible-in-active" ></i>[[ opt.option ]] </button>
</span>

The buttons are are being outputted with names meaning the template tag for naming the button is working but when I click any of the buttons, none is being active meaning the templating tags for ng-click and ng-class are not evaluating. why is this?

Edit
I'm using django so I had to override {{}} with [[]] since django uses these tags too {{}}

I want to achieve THIS. when a button is clicked, it becomes active and the previous active one becomes inactive. This is what am getting JsFiddle

2 Answers 2

1

Inside of ng-click and ng-class you don't need to use data binding operators. You can just say :

<button ng-click="button = opt.option" ng-class="{ active : button == opt.option }">

Also the data binding operator in angular is {{ }} not [[ ]].

Finally, you have a typo and have not closed the opening button tag (you're missing the last '">')

Update - as pointed out the binding operator can be customized so this is not actually an issue.

Update - here's an example plunk: http://plnkr.co/edit/t4hmRmJCI22bjqMe1Jc4?p=preview

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

7 Comments

It should be noted that this is customizable. He could have changed it to [[]] from {{}}.
@JonathanRowny never knew that! Thanks for pointing it out. Any practical use for that feature?
I'm sure there is but not that I can think of... maybe you just hate squiggly brackets? There's an example of how to do it here: docs.angularjs.org/api/ng.$interpolateProvider
It just occurred to me that the "practical use" is that he's using Django templating and doesn't want to escape all those mustaches that Django templates use. So [[]] == client side and {{}} == server side. We're so off topic!
@ksimons I've tried that and still not working. Check the fiddles I have added please.
|
0

You need to use {{ }} not [[ ]]

4 Comments

He probably has overridden $interpolateProvider to use [[]] instead of {{}}. It wouldn't ever work if this wasn't done.
adding an explaination would be nice.
Interesting didn't know that :) Though I don't think he changed, he would have said
@EranH. I'm actually using django so I had to override {{}} with [[]] since django uses these tags too {{}}. I have Edited the question please.

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.