angular icon indicating copy to clipboard operation
angular copied to clipboard

Not reusing existing object problem

Open armanx64 opened this issue 10 years ago • 5 comments

In Angular 1.4.x when I'm trying to call smth like angular.module("myApp") twice, on second call I'm getting error of double initialization, but the right way is just to return previously created object.

Currently because of this behavior we needed to create variable in global context and reuse it; that's not helping to write clean code. If Angular know that module already initialized, so it must return reference to that object. And then instead of

var mainApp = angular.module("mainApp");
....
mainApp.controller(...)

we'll can use

//init
angular.module("mainApp");
....
angular.module("mainApp").controller(...)

And do it in as more places as we want. No more global variables and less code in bootstrappers. Some way can be done with controllers and other points of Angular.

Try to find something wrong in that approach.

armanx64 avatar Jan 11 '16 21:01 armanx64

Since this is a question about Angular 1.4 it should be logged in the angular 1.x project: https://github.com/angular/angular.js

thelgevold avatar Jan 12 '16 03:01 thelgevold

Thanks. But I think this issue is a same for Angular 2. And maybe we'll not get this in Angular 1.x, but it must have for Angular2.

armanx64 avatar Jan 12 '16 08:01 armanx64

Do you have an Angular2 code sample where this would apply?

zoechi avatar Jan 12 '16 08:01 zoechi

this isn't applicable in angular 2, and it's supported in angular1 already?

robwormald avatar Jan 14 '16 08:01 robwormald

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.