0
<input type="text" value="{{codes[0].code}}" ng-click="newNumber(0)" />
<input type="text" value="{{codes[1].code}}" ng-click="newNumber({{codes[1].id}})" />

The first ng-click event fires in my controller just fine but the second one does nothing.

I tried concat'ing as well ... is there some other way I should do this?

2
  • 1
    Try ng-click="newNumber(codes[1].id)". Why you are using value instead of ng-model? Commented Apr 9, 2013 at 21:05
  • I am still trying to grasp the concept of Models in Angular .. I define the $scope.codes object (model) in the controller. Maybe I should go back and re-read....now that I am actuall DOING, its starting to become all a little more clear. Commented Apr 9, 2013 at 21:15

1 Answer 1

2

ng-click

The value of ng-click is already evaluated as an angular expression. As such, you don't need the {{ }}. Read http://docs.angularjs.org/guide/expression for more information. Take a look at the second example, it will help clarify this.

ng-model

Also, ng-model should be used for data-binding. For example, take a look at this jsfiddle: http://jsfiddle.net/bCpW9/8/ and the notes below.

<li ng-repeat="code in codes">

This loops through the codes collection which was defined in the controller. It creates a <li> for each element in the codes collection.

<input ng-model="codes[$index].code" />

Inside each <li>, an <input> for the current code is created. Each input is bound to it's corresponding element in the codes array by setting ng-model to it. For instance, type a new code into the first input field. It automatically updates the corresponding code model with what you typed, as you can see to the right.

I hope that helps.

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

4 Comments

Thank you, great information!!! But I STILL dont know why the function in ng-click should be newNumber(code[$index].id) which works BTW and not newNumber({{code[$index].id}}); ... ?
The value of ng-click is already evaluated as an angular expression. As such, you don't need the {{}}.
Read docs.angularjs.org/guide/expression for more information. Take a look at the second example, it will help clarify this.
BRENT - could you please add this to your answer above so I can check it as answer. Thanks!

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.