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

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -