angularjs - How to load a directive into a module after instantiating using requirejs -
to describe hurdle, little story. injecting requirejs path files(directives basically) contains directive main module in app.js, working perfect. like
define(['angularamd', 'angular-route', 'angular-resource', 'angulartranslate', 'angulartranslateloaderstaticfiles', 'bootstrap', 'angular-idle', 'loadingmaskdirective', 'multiselectdirective', 'treeview.directive', 'tabs', 'checklist.directive'], function(angularamd) { var app = angular.module("myapp", ["ngroute", "ngresource", "ngtable", "myapp.directives", 'ui.bootstrap', 'flow']); app.config(....){ /**some route provider**/ }... angularamd.bootstrap(app); return app;
i have defined directives , injected them main module. want define directive in indivisual controller reduce initial load. there has method. right !!
and code in directive js files looks like..
define(['angular'], function() { angular.module('myapp').directive('somedirective', ['$parse', '$compile', '$rootscope', '$filter', function($parse, $compile, $rootscope, $filter) { .........
so, when try define same in page controller not in app.js, doesn't work. amazed factory function in case works not directive.
any appreciated. thanks
have tried use app create directive?
define(['app'], function(app) { app.directive('somedirective', ['$parse', '$compile', '$rootscope', '$filter', function($parse, $compile, $rootscope, $filter) { .........
an alternative provided angularamd
is:
define(['angularamd'], function(angularamd) { angularamd.directive('somedirective', ['$parse', '$compile', '$rootscope', '$filter', function($parse, $compile, $rootscope, $filter) { .........
the benefit of 2nd approach allow loading of directive before loading of app.js
. see loading application wide module more detail.
Comments
Post a Comment