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 multiple controllers in home #168

Open
ghost opened this issue Apr 11, 2016 · 0 comments
Open

Load multiple controllers in home #168

ghost opened this issue Apr 11, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 11, 2016

Hello
It is possible to load two controllers on the home page ?
I would like to load a controller for the view and one for the index
Here is my code:
`
// application-configuration.js

"use strict";
define(['angularAMD', 'angular-route', 'ui-bootstrap', 'angular-sanitize', ],
function (angularAMD) {

var app = angular.module("mainModule", ['ngRoute', 'ngSanitize', 'ui.bootstrap']);

app.config(['$routeProvider', function ($routeProvider) {

  $routeProvider

  .when("/", angularAMD.route({
    templateUrl: function (rp) { 
      return 'views/home.html'; 
    },               
    controllerUrl: "../boffice/angular/controllers/controller.home"            
  }))

  .when("/:page", angularAMD.route({

    templateUrl: function (rp) { 
     return 'views/' + rp.page + '.html'; },

     resolve: {
      load: ['$q', '$rootScope', '$location', 
      function ($q, $rootScope, $location) {

       var path = $location.path();
       var parsePath = path.split("/");
       //var parentPath = parsePath[1];
       var controllerName = parsePath[1];
       //console.log('controllerName', controllerName);
       var loadController = "../boffice/angular/controllers/controller." + controllerName;

       var deferred = $q.defer();
       require([loadController], function () {
        $rootScope.$apply(function () {
          deferred.resolve();
        });
      });
       return deferred.promise;
     }]
   }
 }))

  .when("/:section/:tree/:id", angularAMD.route({

    templateUrl: function (rp) { 
     return 'views/' + rp.section + '/' + rp.tree + '.html'; },

     resolve: {
      load: ['$q', '$rootScope', '$location', 
      function ($q, $rootScope, $location) {
        var path = $location.path();
        var parsePath = path.split("/");
        var parentPath = parsePath[1];
        var controllerName = parsePath[2];
        var loadController = "Views/" + parentPath + "/" + 
        controllerName + "Controller";

        var deferred = $q.defer();
        require([loadController], function () {
          $rootScope.$apply(function () {
            deferred.resolve();
          });
        });
        return deferred.promise;
      }]
    }
  }))
  .otherwise({ redirectTo: '/' }) 
}]);                

// Bootstrap Angular when DOM is ready
angularAMD.bootstrap(app);

return app;
});

`

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

0 participants