AngularJS: lazy loading controllers and content

后端 未结 9 865
小鲜肉
小鲜肉 2020-12-02 19:00

In this simplified scenario, I have two files: index.htm, lazy.htm.

index.htm:

var myApp = angular.module(\'myApp\', []);
myApp.controller(\'embed\',         


        
9条回答
  •  被撕碎了的回忆
    2020-12-02 19:40

    Ideally - Angular will force you to separate HTML and JS as in newer versions this may be enforced more often.

    You may have to use requireJS http://solutionoptimist.com/2013/09/30/requirejs-angularjs-dependency-injection/

    For the sake of trick can you try

    ng-controller-controller="'lazy'"
    

    or

    In HTML

    ng-controller-controller="myObject.controller"

    Somewhere inject

    $scope.myObject.controller = $controller('lazy', {$scope: $scope})
    

提交回复
热议问题