从呼叫选择Angularjs控制器功能控制器、功能、Angularjs

2023-09-14 00:24:21 作者:? - 、 我非良人

我不知道我怎么能叫我的控​​制器具体取决于在菜单中选择该选项的功能。

I was wondering how I can call a function in my controller depending on the option that is selected in a menu.

例如,使用NG-点击,当单击时,我可以调用该函数。我想要做的选择后,类似的事情在AngularJS。

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> 

任何想法?

推荐答案

与NG-模型中使用NG-变化:

Use ng-change with ng-model:

 <select ng-model="model" ng-change="onSelect()" >

在哪里ONSELECT()是在你的范围的方法。

Where onSelect() is a method on your scope.