Reputation: 31
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>
Upvotes: 2
Views: 39
Reputation: 1296
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 :)
Upvotes: 0
Reputation: 691635
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'
Upvotes: 3