Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

wrong controller instantiation with multiple modules #173

Closed
gruppjo opened this issue Apr 22, 2015 · 9 comments
Closed

wrong controller instantiation with multiple modules #173

gruppjo opened this issue Apr 22, 2015 · 9 comments

Comments

@gruppjo
Copy link
Contributor

gruppjo commented Apr 22, 2015

  1. yo m --skip-prompts
  2. gulp watch

StartCtrl and Service from module main are properly instantiated

  1. yo m:module test
  2. gulp watch
  3. go to http://127.0.0.1:9000/#/main

StartCtrl and Service from module test instead of main are falsely instantiated

This seems to be a general problem with angular since the problem occurred without using ui-router as well and even without controllerAs syntax. However I'm fairly sure this worked correctly in earlier versions.
index.html:

<ion-nav-view>
  <ion-view view-title="main module" ng-controller="StartCtrl as start">
    <ion-content>
      <ion-list>
        <ion-item class="item item-divider">
          This is your start template!
        </ion-item>
        <ion-item class="item item-icon">
          icons working?
          <i class="icon ion-checkmark-circled"></i>
        </ion-item>
        <ion-item class="item item-thumbnail">
          images working?<br>
          <img width="75" src="main/assets/images/[email protected]">
        </ion-item>

        <ion-item class="item">{{start.someData.binding}}</ion-item>
        <ion-item class="item item-divider">Environment variables:</ion-item>
        <ion-item class="item item-text-wrap">
          <pre>{{start.ENV | json}}</pre>
        </ion-item>
        <ion-item class="item item-divider">Build variables:</ion-item>
        <ion-item class="item item-text-wrap">
          <pre>{{start.BUILD | json}}</pre>
        </ion-item>

      </ion-list>
    </ion-content>
  </ion-view>
</ion-nav-view>

main.js

'use strict';
angular.module('main', [
  'ionic',
  'ngCordova',
  'ui.router',
  // TODO: load other modules selected during generation
]);
// .config(function ($stateProvider, $urlRouterProvider) {

//   console.log('Allo! Allo from your module: ' + 'main');

//   $urlRouterProvider.otherwise('/main');

//   // some basic routing
//   $stateProvider
//     .state('main', {
//       url: '/main',
//       templateUrl: 'main/templates/start.html',
//       controller: 'StartCtrl as start'
//     });
//   // TODO: do your thing
// });
@gruppjo gruppjo added the bug label Apr 22, 2015
@gruppjo gruppjo added this to the Q2 2015 milestone Apr 22, 2015
@MathiasTim
Copy link
Contributor

Just checked this out. Same for me here.

But i'm not so sure about the point, that this worked in earlier versions.
I just saw, that it depends, how you 'inject' the modules into each other.

angular.module('myProject', [
  // your modules
  'test',
  'main'
]);

Seems like last one 'wins'.

Apart from this problem, I would prefer a naming of the start controller, service etc in the module name.
This seems far more useful, than 'start' to me.

@gruppjo
Copy link
Contributor Author

gruppjo commented Apr 24, 2015

I'll look into it. Thanks for verifying 👍

@gruppjo
Copy link
Contributor Author

gruppjo commented Apr 24, 2015

Found this: http://stackoverflow.com/questions/13406791/modules-and-name-clashes-in-angularjs/19820088#19820088
In my opinion that's a strong reason against using modules in Angular 1.x, since it renders them pretty much useless and very risky to use. Angular 2 won't have this problem due to ES6 modules I think, because the application programmer is able to manage the naming of the imports her/himself: https://github.com/lukehoban/es6features#modules

@gruppjo
Copy link
Contributor Author

gruppjo commented Apr 29, 2015

related to #148 and #161

@gruppjo
Copy link
Contributor Author

gruppjo commented Apr 29, 2015

@MathiasTim I think naming the start controller, services templates and config constant based on the module name is a good idea. Unfortunately this is quite a bit of work and it also affects how the config constant and its gulp tasks should work. Let's discuss this.

@MathiasTim
Copy link
Contributor

related to: #148

@gruppjo @DrMabuse23 I think we should set up a meeting via Skype, or maybe at M-Way to discuss this. Im not really convinced by our current strategy/use of modules in angular.

@gruppjo gruppjo modified the milestone: Q2 2015 May 20, 2015
@gruppjo
Copy link
Contributor Author

gruppjo commented Jun 11, 2015

Result of discussion:

  • module: name start ctrl, template, service based on module name
  • name config: <moduleName>Config, Config

@gruppjo gruppjo added this to the 1.2.0 milestone Jun 15, 2015
@LunarDevelopment
Copy link

I may be being stupid here, but does this address the issue that each module is created via the yo m:module <modName> command ends up with the view and controllers called 'start'

Which I had to manually rename as my abstract view controller with its default StartCtrl name didnt work as it was clashing with the other module (main)'s controller named StartCtrl

@gruppjo
Copy link
Contributor Author

gruppjo commented Jun 17, 2015

Hi @LunarDevelopment. That exactly is the problem.

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

No branches or pull requests

3 participants