Permalink
Browse files

fix(upgrade): allow attribute selectors for components in ng2 which a…

…re not part of upgrade (#11808)


fixes #11280
  • Loading branch information...
mhevery authored and IgorMinar committed Sep 23, 2016
1 parent 98fac36 commit b81e2e7a31829de3ea0dc56dcb1243425700464e
Showing with 32 additions and 4 deletions.
  1. +6 −3 modules/@angular/upgrade/src/upgrade_adapter.ts
  2. +26 −1 modules/@angular/upgrade/test/upgrade_spec.ts
@@ -401,9 +401,12 @@ export class UpgradeAdapter {
._bootstrapModuleWithZone(
DynamicNgUpgradeModule, undefined, ngZone,
(componentFactories: ComponentFactory<any>[]) => {
- componentFactories.forEach((componentFactory) => {
- componentFactoryRefMap[getComponentInfo(componentFactory.componentType)
- .selector] = componentFactory;
+ componentFactories.forEach((componentFactory: ComponentFactory<any>) => {
+ var type: Type<any> = componentFactory.componentType;
+ if (this.upgradedComponents.indexOf(type) !== -1) {
+ componentFactoryRefMap[getComponentInfo(type).selector] =
+ componentFactory;
+ }
});
})
.then((ref: NgModuleRef<any>) => {
@@ -964,6 +964,31 @@ export function main() {
}));
});
+ it('should allow attribute selectors for components in ng2', async(() => {
+ const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => MyNg2Module));
+ var ng1Module = angular.module('myExample', []);
+
+ @Component({selector: '[works]', template: 'works!'})
+ class WorksComponent {
+ }
+
+ @Component({selector: 'root-component', template: 'It <div works></div>'})
+ class RootComponent {
+ }
+
+ @NgModule({imports: [BrowserModule], declarations: [RootComponent, WorksComponent]})
+ class MyNg2Module {
+ }
+
+ ng1Module.directive('rootComponent', adapter.downgradeNg2Component(RootComponent));
+
+ document.body.innerHTML = '<root-component></root-component>';
+ adapter.bootstrap(document.body.firstElementChild, ['myExample']).ready((ref) => {
+ expect(multiTrim(document.body.textContent)).toEqual('It works!');
+ ref.dispose();
+ });
+ }));
+
describe('examples', () => {
it('should verify UpgradeAdapter example', async(() => {
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
@@ -994,7 +1019,7 @@ export function main() {
document.body.innerHTML = '<ng2 name="World">project</ng2>';
- adapter.bootstrap(document.body, ['myExample']).ready((ref) => {
+ adapter.bootstrap(document.body.firstElementChild, ['myExample']).ready((ref) => {
expect(multiTrim(document.body.textContent))
.toEqual('ng2[ng1[Hello World!](transclude)](project)');
ref.dispose();

0 comments on commit b81e2e7

Please sign in to comment.