javascript - Reusing directives for multiple modules -
i know best way reuse same directive multiple modules. in mind think directives dom-modules, architecture of angular bit annoying of point of view.
the way i'm doing is:
var mainapp = angular.module('mainapp'); mainapp.controller( ... ); var otherapp = angular.module('otherapp'); otherapp.controller( ... );
and in other file have directive want utilize in 2 controllers/modules
mainapp.directive('autoselect', function(){ ... });
but can see, have specify in app have utilize it. if want utilize in both, have re-create twice same code?
you can maintain module contains mutual (services, directives, values, constants etc.) , inject each module.
angular.module('commonapp',['othercommonmodule1','othercommonmodule2']).directive(..); var mainapp = angular.module('mainapp', ['commonapp']); mainapp.controller( ... ); var otherapp = angular.module('otherapp', ['commonapp']); otherapp.controller( ... );
javascript angularjs angularjs-directive
No comments:
Post a Comment