Answer the question
In order to leave comments, you need to log in
How to dynamically load controllers in Angular?
I am using AngularUI Router .
In templates I use the following code:
<section data-ng-controller="FooBarCtrl">
<!-- content -->
</section>
// state выглядит примерно так
{name: 'foo', url: '/foo', templateUrl: '/app/views/foo.html', pageTitle: 'Foo', files: {js: ['/app/controllers/foobar.js']}}
// код внутри run()
$rootScope.$on('$stateChangeStart', function(event, state) {
// тут хочу подгрузить данные из state.files.js
});
Answer the question
In order to leave comments, you need to log in
In fact, this is not only the task of loading controllers, but also other modules (factories, directives...). When developing the first application in angular, the question of asynchronous loading of components also arose.
There is a great example here .
In general, when configuring an application, we say which modules need to be resolved before going through the route. And dynamic loading falls on the shoulders of RequireJS.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question