Search code examples
angularjsdependency-injectionloadoclazyload

Load on demand controller js file with ocLazyLoad in AngularJS


I have problem in load on demand controller js file with ui-router and error me:

Argument 'FormController' is not a

My code is:

'use strict';

var Request = angular.module('Request',['ui.router','oc.lazyLoad'])
    .config(function($stateProvider) {
        $stateProvider.state('form', {
            url: "/form",
            templateUrl: "view/form1.html",
            controller:'FormController as form',
            resolve: {
                form: function( $ocLazyLoad ){
                    return $ocLazyLoad.load(
                        {
                            name:'form',
                            files:['app/controller/FormController.js']
                        }
                    )
                }

        }
    });

and my controller is:

'use strict';

Request.controller('FormController',function($scope){
    $scope.text = 'This is Form Controller';
})

Solution

  • I solved problem with this solution:

    Change app.controller to angular.module('myApp').controller

    https://github.com/ocombe/ocLazyLoad/issues/182