angularjs - How to access directive parameter in Angular JS? -


i'm pretty new angular , have run slight problem. have simple datepicker directive works

app.directive('datepicker', function() {     return {         require: 'ngmodel',         link: function(scope, elem, attr, ngmodel){         $(elem).datepicker({             onselect: function(datetext){                 scope.$apply(function(){                     ngmodel.$setviewvalue(datetext);                 });             }         });         }     } }); 

and html use call is

<input datepicker data-ng-model="day.date" readonly/>  

i able change onselect function called datepicker – this.

<input datepicker="myonselectmethod()" data-ng-model="day.date" readonly/> 

then directive this

app.directive('datepicker', function() {     return {         require: 'ngmodel',         link: function(scope, elem, attr, ngmodel){             if(myonselectmethod defined){ //how access myonselectmethod here?                 $(elem).datepicker({                     onselect: myonselectmethod();                 });             }             else{ //proceed before                 $(elem).datepicker({                     onselect: function(datetext){                         scope.$apply(function(){                             ngmodel.$setviewvalue(datetext);                         });                     }                 });             }         }     } }); 

so question is: how access new onselect function want execute link function?

looking through docs , other questions seems should possible haven't been able make work. i've come ugly workaround using ng-click activate datepicker on given element, learn how make work if possible. thanks!

you can check way:

if( attr["datepicker"] == "myonselectmethod" &&      typeof myonselectmethod === "function" ){       // ... } 

or even:

if( typeof scope[attr["datepicker"]] === "function" ){ // instead of `scope`      // ...                                             // may other object, }                                                      // `window` example 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -