user1177440
user1177440

Reputation:

ocLazyLoad - one controller calling another

In my header.html I have 2 controllers, header controller and language controller.

This is my HeaderCtrl:

define(
[
    'angular', 'layout/layout.module','languages/languages.module',    
    'languages/controllers/LanguagesCtrl'
],
function (angular) {
'use strict';

angular.module('app.layout').controller('HeaderCtrl', HeaderCtrl);

/* @ngInject */
function HeaderCtrl() {
    var header = this;
    header.pageTitle = 'Response coming from HeaderCtrl';
}

});

My State: (via svc call to json file)

 "header": {
              "templateUrl": "app/layout/views/tpl.header.html",
              "controller": "HeaderCtrl as header",
              "resolve": {},
              "data": {
                "moduleName": "app.layout",
                "moduleFiles": [
                  "app/languages/controllers/HeaderCtrl.js"
                ]
              }

Question:

How can I pass scope from LanguagesCtrl to HeaderController so my html has both HeaderCtrl & LanguagesCtrl scope, without requiring a click event? [Because of the HeaderController's defines, LanguageController is loading, I just cannot communicate with it.]

Upvotes: 0

Views: 250

Answers (1)

user1177440
user1177440

Reputation:

I have a solution with a caveat:

If you go to the github for angularjs-requirejs-lazy-controllers, there is a mbLazyController directive that does the job.

The caveat:

As near as I can tell / have tried, you cannot have a "Controller as" scenario so you have to use $scope:

  <div mb-lazy-controller="languages/controllers/LanguagesCtrl">
  {{message}}     
  </div>

But it does do the job and works with AngularJs 1.3.2.

Upvotes: 1

Related Questions