Skip to content
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

fix(upgrade): component injectors should not link the module injector… #15385

Merged
merged 1 commit into from
Mar 22, 2017

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Mar 22, 2017

No description provided.

return notFoundValue;
}

return this.injector.get(token);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass notFoundValue here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, thanks !

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (just a couple of nits)


let componentInjector: Injector;

@Component({selector: 'ng2', template: '[<ng-content></ng-content>]'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: No need for <ng-content> (afaict). You can just have 'ng2' (or an empty template if you don't care about it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I tried many things before coming to this test... will remove

}

const ng1Module = angular.module('ng1', [])
.directive('ng1', () => ({template: '<ng2></ng2>'}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: No need for this directive. You can use const element = html('<ng2></ng2>') below instead.


const element = html('<ng1></ng1>');

platformBrowserDynamic().bootstrapModule(Ng2Module).then((modRef) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You could probably use the bootstrap helper (and save two whole lines of code 😛):

bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module).then(upgrade => {
  const modInjector = upgrade.injector;
  // Emulate the router lazy loading ...
  ...
});

constructor(private modInjector: Injector) {}

// When Angular locate a service in the component injector tree, the not found value is set to
// `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR` in such a case we should not walk up to the module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a . before in such case

const compiler = modInjector.get(Compiler);
const modFactory = compiler.compileModuleSync(LazyLoadedModule);
const childMod = modFactory.create(modInjector);
const cmpFactory = childMod.injector.get(ComponentFactoryResolver)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

childMod.componentFactoryResolver

@@ -361,5 +361,55 @@ export function main() {
expect(multiTrim(document.body.textContent)).toBe('parent(child)');
});
}));

it('should work with ng2 lazy loaded components=', async(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: components= --> components

@vicb vicb added the action: merge The PR is ready for merge by the caretaker label Mar 22, 2017
@IgorMinar IgorMinar merged commit ea49a95 into angular:master Mar 22, 2017
@vicb vicb deleted the 0322-upInjTake2 branch May 19, 2017 17:28
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants