javascript - How to refactor directive code in angularJS -


i coming .net world may missing obvious in javascript world in angularjs. writing few directives , have same kind of code need setup same attributes.

is possible create function , use function inside link function of angular?

thanks

ofcourse, not hard javascript.

here example code that.

(function(){     function commoncode(){         //common code goes here.     }      var app = angular.module("app");      app.directive("first",function(){         return function(scope,element,attrs){             commoncode();         }     });       app.directive("second",function(){         return function(scope,element,attrs){             commoncode();         }     });      app.directive("third",function(){         return function(scope,element,attrs){             commoncode();         }     });  })(); 

and easier angularjs.

if common code extremely generic, refactor out commoncode service , inject directives.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

php - Boolean search on database with 5 million rows, very slow -

css - Text drops down with smaller window -