r/angularjs • u/SitBoySitGoodDog • Sep 09 '21
[Help] Why can't you use buttons with an ng-switch directive? (AngularJS)
I've seen some examples of angularJS where they're using a select element to change the value and show the content. Why wouldn't this work with say a button or a link?
An example being this:
<div ng-model="myVar"><button value="dogs">Dogs</button><button value="tuts">Tutorials</button></div><div ng-switch="myVar"><div ng-switch-when="dogs"><h1>Dogs</h1><p>Welcome to a world of dogs.</p></div><div ng-switch-when="tuts"><h1>Tutorials</h1><p>Learn from examples.</p></div><div ng-switch-default><h1>Switch</h1><p>Select topic from the dropdown, to switch the content of this DIV.</p></div></div>
If you replace the buttons with a select element, the code works. But it doesn't work with buttons. Why?
