fix(core): don’t set ng-version
for dynamically created components (#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 #15880 PR Close #16394
This commit is contained in:
parent
aa8bba4865
commit
a4de214e2b
@ -90,7 +90,9 @@ class ComponentFactory_ extends ComponentFactory<any> {
|
|||||||
const view = Services.createRootView(
|
const view = Services.createRootView(
|
||||||
injector, projectableNodes || [], rootSelectorOrNode, viewDef, ngModule, EMPTY_CONTEXT);
|
injector, projectableNodes || [], rootSelectorOrNode, viewDef, ngModule, EMPTY_CONTEXT);
|
||||||
const component = asProviderData(view, componentNodeIndex).instance;
|
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);
|
return new ComponentRef_(view, new ViewRef_(view), component);
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,10 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {TestBed, fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {By} from '@angular/platform-browser';
|
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';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
@ -365,6 +366,23 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||||||
expect(testDirs[1].tpl).toBeDefined();
|
expect(testDirs[1].tpl).toBeDefined();
|
||||||
expect(testDirs[2].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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user