0

below is my snippet in my directive which calls a controller

element.bind('change', function() {
    //alert("inside change function");
    $rootScope.selectedBankName = scope.selectedBankName;
    newvalue = scope.selectedBankName;
    $timeout(function() {
        scope.changeClient();
    }, 500);
});

If I use above code It is calling changeclient() function for every element change. but my requirement is I need to call the changeClient function when I change the value in the select box only.please suggest me how to do this.

EDIT:

http://plnkr.co/edit/clTJjlZRlErskt6T0Foc?p=preview

please find the plunker code when I change some value in textbox or dropdown and click any where it is displaying alert box. But my requirement is the alert should be displayed only when I change dropdown value and click anywhere(not for textbox).

4

1 回答 1

0

如果您想在下拉模型更改时触发事件,您实际上不需要选择编写指令。只需在选择上添加一个观察者并等待更改

$scope.$watch('age',function(newVal){
    $scope.loadMoreTweets();
});

Plunker:http ://plnkr.co/edit/j3ZR32c4G8PpbLEtrFpZ?p=preview

编辑:

如果您真的选择使用指令代码,则可以将指令应用于选择本身,而不是其父 div

<select enter>
于 2014-07-15T09:13:01.060 回答