Skip to content

Commit

Permalink
fix(core): don’t set ng-version for dynamically created components (a…
Browse files Browse the repository at this point in the history
…ngular#16394)

Angular uses the `ng-version` attribute to indicate which elements
were used to bootstrap an application. However, after 4.0 we also
added this attribute for all dynamically created components.

Fixes angular#15880

PR Close angular#16394
  • Loading branch information
tbosch authored and juleskremer committed Aug 24, 2017
1 parent 122c481 commit 80d192f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/view/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class ComponentFactory_ extends ComponentFactory<any> {
const view = Services.createRootView(
injector, projectableNodes || [], rootSelectorOrNode, viewDef, ngModule, EMPTY_CONTEXT);
const component = asProviderData(view, componentNodeIndex).instance;
view.renderer.setAttribute(asElementData(view, 0).renderElement, 'ng-version', VERSION.full);
if (rootSelectorOrNode) {
view.renderer.setAttribute(asElementData(view, 0).renderElement, 'ng-version', VERSION.full);
}

return new ComponentRef_(view, new ViewRef_(view), component);
}
Expand Down
20 changes: 19 additions & 1 deletion packages/core/test/linker/regression_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ContentChild, Directive, InjectionToken, Injector, Input, Pipe, PipeTransform, Provider, QueryList, Renderer2, SimpleChanges, TemplateRef, ViewChildren, ViewContainerRef} from '@angular/core';
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ContentChild, Directive, InjectionToken, Injector, Input, NgModule, NgModuleRef, Pipe, PipeTransform, Provider, QueryList, Renderer2, SimpleChanges, TemplateRef, ViewChildren, ViewContainerRef} from '@angular/core';
import {TestBed, fakeAsync, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {expect} from '@angular/platform-browser/testing/src/matchers';

export function main() {
Expand Down Expand Up @@ -365,6 +366,23 @@ function declareTests({useJit}: {useJit: boolean}) {
expect(testDirs[1].tpl).toBeDefined();
expect(testDirs[2].tpl).toBeDefined();
});

it('should not add ng-version for dynamically created components', () => {
@Component({template: ''})
class App {
}

@NgModule({declarations: [App], entryComponents: [App]})
class MyModule {
}

const modRef = TestBed.configureTestingModule({imports: [MyModule]})
.get(NgModuleRef) as NgModuleRef<MyModule>;
const compRef =
modRef.componentFactoryResolver.resolveComponentFactory(App).create(Injector.NULL);

expect(getDOM().hasAttribute(compRef.location.nativeElement, 'ng-version')).toBe(false);
});
});
}

Expand Down

0 comments on commit 80d192f

Please sign in to comment.