pbastowski / angular2-now

Angular 2 @Component syntax for Angular 1 apps
MIT License
145 stars 15 forks source link

race condition in setting angular.module to SetModule; #8

Closed Huck closed 9 years ago

Huck commented 9 years ago

We are using angular2-now and its pretty amazing.

we found a bug where there seems to be a race condition between angular and angular2-now where angular.module is not always set to SetModule; By using angualr2now the usual way, our app doesnt always load becuase this override of angular.module is not always set. When we add the below code at the top of out .ts file to our app, then it loads correctly every time:

angular.module = angular2now.SetModule;

example in typescript with system.js transpiling:

import * as angular2now from 'angular2-now';

var {Component, View, bootstrap} = angular2now;

console.log(angular.version); angular2now.options({ controllerAs: 'vm' }); // this below seems to be very important due to a bug in angular2-now angular.module = angular2now.SetModule;

angular.module('foo', [ ]);

class ...

bootstrap...

pbastowski commented 9 years ago

Are you perhaps lazy-loading the library (with systemjs/jspm)? The problem could be with angular2-now loading and executing before AngularJS does.

I have not encountered this issue as yet myself. However, my code is always bundled and sequenced in the bundle in dependency order, with angular2-now depending on AngularJS. So, AngularJS always loads before angular2-now.

How do you bundle your code and in what order does it load?

Huck commented 9 years ago

Hi, thanks for the prompt answer.

yes, we are using System.js to load the library, although we ensure that shim/meta configs are properly set to ensure angular2-now loads after angular.

pbastowski commented 9 years ago

Without seeing your code it is difficult for me to diagnose it. But, I have an idea.

Could you try the following for me: in every module where you use angular2-now annotations, replace angular.module with SetModule.

Does this help solve the issue?

Note: I am going to deprecate the monkey-patching on angular.module due to a separate issue, so, it is best to use SetModule from now on anyway.

Huck commented 9 years ago

Hi,

replacing all angular.module with angular2now.SetModule('foo',[]); works like a charm. We will stick to this from now on.

by the way, thanks for your library, its really nice.

regards