admin管理员组文章数量:1391975
I was wondering how I can call a function in my controller depending on the option that is selected in a menu.
For instance, using ng-click, when a is clicked, I can call the function. I want to do something similar upon selection in AngularJS.
<select class="dropdown">
<option value="">Menu</option>
<option ng-click="open()">Settings</option> // call open() when Settings is selected
</select>
Any ideas?
I was wondering how I can call a function in my controller depending on the option that is selected in a menu.
For instance, using ng-click, when a is clicked, I can call the function. I want to do something similar upon selection in AngularJS.
<select class="dropdown">
<option value="">Menu</option>
<option ng-click="open()">Settings</option> // call open() when Settings is selected
</select>
Any ideas?
Share Improve this question asked Jun 17, 2014 at 0:04 kevinkevin 1651 gold badge2 silver badges8 bronze badges 1-
You can use
ng-model
and$watch
for a change in that model. – Evandro Silva Commented Jun 17, 2014 at 0:08
2 Answers
Reset to default 4Use ng-change with ng-model:
<select ng-model="model" ng-change="onSelect()" >
Where onSelect() is a method on your scope.
<select ng-model="whatever">
<option value="settings">Settings</option>
</select>
In your controller:
$scope.$watch('whatever', function(newValue, oldValue) {
if (newValue == 'settings') {
doSomething();
}
});
本文标签: javascriptCall Controller Function from Select AngularjsStack Overflow
版权声明:本文标题:javascript - Call Controller Function from Select Angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744725025a2621910.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论