-
Notifications
You must be signed in to change notification settings - Fork 25.3k
-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
upgradeAdapter.bootstrap throws TypeError: Cannot read property 'injector' of null #10656
Comments
I ended up getting it working by following one of the examples in upgrade_adapter.js var adapter = new UpgradeAdapter(forwardRef(() => MyNg2Module));
var module = angular.module('myExample', []);
module.directive('greet', function() {
return {
scope: {salutation: '=', name: '=' },
template: '{{salutation}} {{name}}! - <span ng-transclude></span>'
};
});
module.directive('ng2', adapter.downgradeNg2Component(Ng2));
@Component({
selector: 'ng2',
template: 'ng2 template: <greet salutation="Hello" [name]="world">text</greet>'
})
class Ng2 {
}
@NgModule({
declarations: [Ng2, adapter.upgradeNg1Component('greet')],
imports: [BrowserModule]
})
class MyNg2Module {}
document.body.innerHTML = '<ng2></ng2>';
adapter.bootstrap(document.body, ['myExample']).ready(function() {
expect(document.body.textContent).toEqual("ng2 template: Hello world! - text");
}); |
What about upgrading Angular 1 providers? Should I add the following to the NgModule metadata? providers: [ adapter.upgradeNg1Provider('token') ] Any suggestions? |
@ptomaszi I'm where you are. I got past my MANY MANY other errors related to RC5 and UpgradeAdapter, but now am getting a "No provider for ..." for my angular 1 services. This of course was all working on RC4. You can't use:
As upgradeNg1Provider returns void. |
@dparish see #10723 (comment) to know how to use |
@marcalj I'll try that. I can see that you are using a const to give access to the upgradeAdapter to the rest of the code base.
Are you then referencing upgradeAdapter from the rest of the app or creating a new instance of upgradeAdapter in other portions of the app? |
@dparish Referencing it, for example: import {upgradeAdapter} from './app.module';
upgradeAdapter.upgradeNg1Provider('$filter'); |
This bug is the same as #10879 . Some workarounds are posted there. Although the setTimeout workaround is not really nice. Because of it, I can't use angular.run() callbacks that use any kind of services that are or depend on ng2 downgraded services, as it will issue the bug. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Everything was working OK in 2.0.0-rc.4. I upgrade to rc5 and noticed the new ngModules. I went through and added ng modules along with AppModule where appropriate and instantiated the upgradeAdapter like so:
Current behavior
My app fails to bootstrap. The error shown in the javascript console is:
upgrade_adapter.js:326 Uncaught TypeError: Cannot read property 'injector' of null
Expected/desired behavior
The app bootstraps successfully.
Reproduction of the problem
Am I the only person this fails for? If so, I'll put something up.
Please tell us about your environment:
I looked at the code in upgrade_adapter.js that was erroring and noticed that moduleRef gets set after a call to platform_browser_dynamic_1.platformBrowserDynamic(). So I went ahead and added this hoping that's what I needed to make the null ref error go away:
Now I have another error:
browser_adapter.js:84EXCEPTION: The module AppModule was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. Please define one of these.
The thing is, I don't have any ng2 components to add here. Currently, my app is mostly ng1 with some ng2 providers that I downgrade to be used in ng1 using the upgradeAdapter. That setup worked in rc4.
The text was updated successfully, but these errors were encountered: