2

There is clearly something fundamental but I can't search any other useful posts on this.

For first case, it worked as expected. When click on button B, I am getting 2. For second case, it is not working anymore when I changed the numbers to A&B. Please find the code as below.

First Case

<p>Click the button:</p>

<button ng-click="name = 1" ng_init="name=0">A</button>
<button ng-click="name = 2" ng_init="name=0">B</button>

<p>This is {{name}}.</p>

Second Case

<p>Click the button:</p>

<button ng-click="name = A" ng_init="name=0">A</button>
<button ng-click="name = B" ng_init="name=0">B</button>

<p>This is {{name}}.</p>
1
  • I guess it is not ng_init..... it is ng-init Commented Aug 31, 2016 at 15:58

2 Answers 2

3
name = A

assigns the value of $scope.A to $scope.name. I assume you don't have any property named A in the scope, so name is set to undefined. You probably want

name = 'A'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! it works after putting in the single quote.
0

A and B are probably strings, so you should assign it as a string.

<button ng-click="name = 'A' " ng_init="name=0">A</button>
<button ng-click="name = 'B' " ng_init="name=0">B</button>

Hope it helps :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.