sukesh
sukesh

Reputation: 2437

Can the ng-model value be changed from another element's event - angularjs

I would like to change the selected value of dropdown when user clicks on the anchor tags. Is it possible.

Something like

<a href ng-click="{SelectedPage=SelectedPage-1}">Prev</a>
<select ng-model="SelectedPage">
 <option value="1">1</option>
 <option value="2">2</option>
 <option value="3">3</option>
</select>
<a href ng-click="{SelectedPage=SelectedPage+1}">Next</a>

For example, when the value selected in dropdown is 2, and user clicks on Next, the selection in dropdown changes to 3 & also $scope.SelectedPage becomes 3.

Upvotes: 0

Views: 40

Answers (1)

Vineet
Vineet

Reputation: 4655

Yes it is possible. Just use

<a href ng-click="SelectedPage=SelectedPage-1">Prev</a>

and

<a href ng-click="SelectedPage=SelectedPage+1">Next</a>

Without { & } You should use ng-href instead of href. See ng-href

Upvotes: 2

Related Questions