1

The following code is giving me Error: [$parse:syntax] in console.

          <ul class="nav navbar-nav" ng-repeat="webpage in first.webpages">
            <li><a  href ng-click="tab = {{webpage.id}}">{{webpage.name}}</a></li>
          </ul>

ng-repeat is properly working for {{webpage.name}} only, not for {{webpage.id}} which is placed inside ng-click directive. When I try to print {{tab}} nothing shows up.

2 Answers 2

1

I believe you don't need double braces inside angular elements. And you need to call the parent scope when in ng-repeat :

ng-click="$parent.tab = webpage.id"
Sign up to request clarification or add additional context in comments.

3 Comments

Alright, you're actually in the wrong scope when using tab in ng-repeat. To get it in your main scope, use $parent.tab.
thanks, {{tab}} works inside the tag with ng-repeat only. Why its scope its only under ng-repeat only. I am going to use "ng-show="tab === 1" out of ng-repeat's scope, how to do it?
If you use $parent.tab in your ng-click, you should be able to grab it from outside the ng-repeat with {{tab}}
1

It should be:

      <ul class="nav navbar-nav" ng-repeat="webpage in first.webpages">
        <li><a  href ng-click="tab = webpage.id">{{webpage.name}}</a></li>
      </ul>

You don't need to interpolate anything when you are inside ng-click since it does it for you.

1 Comment

Not working, I get <a href="" ng-click="tab = webpage.id" class="ng-binding">Home</a> when I inspect the element using Chrome's dev tools. printing {{tab}} also shows nothing.

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.