Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load controller without app #102

Closed
gibson opened this issue Dec 22, 2014 · 5 comments
Closed

Load controller without app #102

gibson opened this issue Dec 22, 2014 · 5 comments

Comments

@gibson
Copy link

gibson commented Dec 22, 2014

I have app and controller in different files, app loaded before app started, controller is a depency.

app code

ng.module('app.auth', ['ui.router', 'oc.lazyLoad']).config(function ($stateProvider) {
        $stateProvider.state('login', {
            url: '/login',
            views: {
                root: {
                    templateUrl: 'views/auth/login.html'
                }
            },
            data: {
                title: 'Login',
                htmlId: 'extr-page'
            },
            controller: 'LoginCtrl',
            resolve: {
                LoginCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load({
                        name: 'app.auth',
                        files: [
                            'controllers/LoginCtrl',
                            'js/modules/forms/directives/validate/smartValidateForm'
                        ]
                    });
                }]
            }
        });


    });

ctrl code

define([
        'modules/auth',
        'lodash'
    ],
    function (module, _) {
        "use strict";
        module.controller('LoginCtrl', function ($scope, Auth, $state, $rootScope) {
            $scope.remember = true;
            $scope.login = function () {
                Auth.login({
                    email: $scope.username,
                    password: $scope.password
                }, function (user) {
                    console.log(user);
                    $rootScope.$state.go(_.first(user.modules).href);
                }, function (err) {
                    $rootScope.error = err;
                });
            };
        });

        return module;
    });

and when oclazyload require ctrl and inject him to app he reloading app (app already loaded) and angular has a error "State 'login'' is already defined"

i tested with params

reconfig: false,
rerun:false,

and add app.auth to loadedModules
problem not solved

@gibson
Copy link
Author

gibson commented Dec 22, 2014

in my opinion if module (app.auth) in loadedModules we should not load this module again

@ocombe
Copy link
Owner

ocombe commented Dec 23, 2014

Hi, if you use define then you probably use bootstrap to start your app. You need to let the app know what the name of your main module is. From the docs:

loadedModules: If you use angular.bootstrap(...) to launch your application, you need to define the main app module as a loaded module.

angular.bootstrap(document.body, ['test']);
$ocLazyLoadProvider.config({
    loadedModules: ['test']
});

@gibson
Copy link
Author

gibson commented Dec 23, 2014

i define that module in loaded modules - not working

$ocLazyLoadProvider.config({
    loadedModules: ['app.layout', 'app.auth'],
    jsLoader: requirejs,
    debug: true
});

@ocombe
Copy link
Owner

ocombe commented Dec 23, 2014

Hmm that weird, is your app available somewhere so that I could check it out ? Or can you make me a plunkr ?

@ocombe ocombe closed this as completed in 01936cd Dec 30, 2014
@ocombe
Copy link
Owner

ocombe commented Dec 30, 2014

Check 0.5.2 I think that it should fix your bug :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants