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
Post a Comment