AngularJS Dynamic loading a controller

前端 未结 1 1479
忘掉有多难
忘掉有多难 2020-12-03 00:16

I read a lot about lazzy loading, but I am facing a problem when using $routeProvider.

My goal is to load a javascript file which contains a controller and add a rou

相关标签:
1条回答
  • 2020-12-03 00:51

    Re-reading this article http://ify.io/lazy-loading-in-angularjs/ suggested to keep a $contentProvider instance inside Angular App.

    I came up with this code in my app.js

    demoApp.config(function ($controllerProvider) {
         demoApp.controller = $controllerProvider.register;
    });
    

    It enables me to write my controller as expected in a external javascript file :

    angular.module("demoApp").controller('MouseTestCtrlA', fn);
    

    Hope this can help !

    0 讨论(0)
提交回复
热议问题