AngularJS : How to trigger an action on select option? -
i new in angular. seek print form. in form have select input. dont know how action when user select option. want retrieve datas server when select alternative made. need illustration please.
you can write directive :
yourapp.directive('changed',function(){ homecoming function(scope,elem,att){ elem.bind('change',function(){ alert('hi'); }) } }); and can utilize in view :
selcet tag here : <select changed> <option value="1">1</option> <option value="2">2</option> </select> also if want pass select directive can :
<select changed="passthis"> <option value="1">1</option> <option value="2">2</option> </select> and in directive can ever you've sent:
yourapp.directive('changed',function(){ homecoming function(scope,elem,att){ elem.bind('change',function(){ // below alert: "passthis" alert(att.changed); // bellow alert ever alternative user has choosed alert(elem.value()); }) } }); you want run $http request on selection changed ? easy :
yourapp.directive('changed',function($http){//notice here injected $http homecoming function(scope,elem,att){ elem.bind('change',function(){ $http.post('yoururl',{yourdatatosend}) .success(function(msg){ alert("msg backend: ",msg) }).error(function(){ alert('error'); }) }) } }); angularjs
No comments:
Post a Comment