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).
If you want to trigger an event when the dropdown model is changed, you don't really need to choose to write a directive. Just add a watcher on the select and wait for changes
$scope.$watch('age',function(newVal){
$scope.loadMoreTweets();
});
Plunker: http://plnkr.co/edit/j3ZR32c4G8PpbLEtrFpZ?p=preview
Edit:
If you really choose to go with the directive code, you can apply the directive on the select itself instead if its parent div
<select enter>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.