feat(ivy): implement the getters of ViewContainerRef (#25174)
BREAKING CHANGE: ViewContainerRef.parentInjector is deprecated without replacement PR Close #25174
This commit is contained in:
@ -44,6 +44,9 @@
|
||||
{
|
||||
"name": "EMPTY_RENDERER_TYPE_ID"
|
||||
},
|
||||
{
|
||||
"name": "ElementRef"
|
||||
},
|
||||
{
|
||||
"name": "ElementRef$1"
|
||||
},
|
||||
@ -98,6 +101,12 @@
|
||||
{
|
||||
"name": "NgModuleRef"
|
||||
},
|
||||
{
|
||||
"name": "NodeInjector"
|
||||
},
|
||||
{
|
||||
"name": "NullInjector"
|
||||
},
|
||||
{
|
||||
"name": "Optional"
|
||||
},
|
||||
@ -173,6 +182,9 @@
|
||||
{
|
||||
"name": "ViewContainerRef$1"
|
||||
},
|
||||
{
|
||||
"name": "ViewContainerRef$1"
|
||||
},
|
||||
{
|
||||
"name": "ViewEncapsulation$1"
|
||||
},
|
||||
@ -191,6 +203,9 @@
|
||||
{
|
||||
"name": "_ROOT_DIRECTIVE_INDICES"
|
||||
},
|
||||
{
|
||||
"name": "_THROW_IF_NOT_FOUND"
|
||||
},
|
||||
{
|
||||
"name": "__read"
|
||||
},
|
||||
@ -494,6 +509,9 @@
|
||||
{
|
||||
"name": "getCleanup"
|
||||
},
|
||||
{
|
||||
"name": "getClosestComponentAncestor"
|
||||
},
|
||||
{
|
||||
"name": "getCurrentSanitizer"
|
||||
},
|
||||
@ -515,12 +533,18 @@
|
||||
{
|
||||
"name": "getNextLNode"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateChangeDetectorRef"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateContainerRef"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateElementRef"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateHostChangeDetector"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateInjectable"
|
||||
},
|
||||
@ -617,6 +641,9 @@
|
||||
{
|
||||
"name": "invertObject"
|
||||
},
|
||||
{
|
||||
"name": "isComponent"
|
||||
},
|
||||
{
|
||||
"name": "isContextDirty"
|
||||
},
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, ComponentFactoryResolver, Directive, EmbeddedViewRef, NgModuleRef, Pipe, PipeTransform, RendererFactory2, TemplateRef, ViewContainerRef, createInjector, defineInjector, ɵAPP_ROOT as APP_ROOT, ɵNgModuleDef as NgModuleDef} from '../../src/core';
|
||||
import {Component, ComponentFactoryResolver, ElementRef, EmbeddedViewRef, NgModuleRef, Pipe, PipeTransform, RendererFactory2, TemplateRef, ViewContainerRef, createInjector, defineInjector, ɵAPP_ROOT as APP_ROOT, ɵNgModuleDef as NgModuleDef} from '../../src/core';
|
||||
import {getOrCreateNodeInjectorForNode, getOrCreateTemplateRef} from '../../src/render3/di';
|
||||
import {AttributeMarker, NgOnChangesFeature, defineComponent, defineDirective, definePipe, injectComponentFactoryResolver, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index';
|
||||
import {bind, container, containerRefreshEnd, containerRefreshStart, element, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, interpolation1, interpolation3, load, loadDirective, nextContext, projection, projectionDef, reserveSlots, text, textBinding} from '../../src/render3/instructions';
|
||||
@ -1035,6 +1035,66 @@ describe('ViewContainerRef', () => {
|
||||
'<p vcref=""></p><embedded-cmp-with-ngcontent>12<hr>34</embedded-cmp-with-ngcontent>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getters', () => {
|
||||
it('should work on elements', () => {
|
||||
function createTemplate() {
|
||||
elementStart(0, 'header', ['vcref', '']);
|
||||
elementEnd();
|
||||
elementStart(1, 'footer');
|
||||
elementEnd();
|
||||
}
|
||||
|
||||
new TemplateFixture(createTemplate, undefined, [DirectiveWithVCRef]);
|
||||
|
||||
expect(directiveInstance !.vcref.element.nativeElement.tagName.toLowerCase())
|
||||
.toEqual('header');
|
||||
expect(
|
||||
directiveInstance !.vcref.injector.get(ElementRef).nativeElement.tagName.toLowerCase())
|
||||
.toEqual('header');
|
||||
expect(() => directiveInstance !.vcref.parentInjector.get(ElementRef)).toThrow();
|
||||
});
|
||||
|
||||
it('should work on components', () => {
|
||||
const HeaderComponent =
|
||||
createComponent('header-cmp', function(rf: RenderFlags, ctx: any) {});
|
||||
|
||||
function createTemplate() {
|
||||
elementStart(0, 'header-cmp', ['vcref', '']);
|
||||
elementEnd();
|
||||
elementStart(1, 'footer');
|
||||
elementEnd();
|
||||
}
|
||||
|
||||
new TemplateFixture(createTemplate, undefined, [HeaderComponent, DirectiveWithVCRef]);
|
||||
|
||||
expect(directiveInstance !.vcref.element.nativeElement.tagName.toLowerCase())
|
||||
.toEqual('header-cmp');
|
||||
expect(
|
||||
directiveInstance !.vcref.injector.get(ElementRef).nativeElement.tagName.toLowerCase())
|
||||
.toEqual('header-cmp');
|
||||
expect(() => directiveInstance !.vcref.parentInjector.get(ElementRef)).toThrow();
|
||||
});
|
||||
|
||||
it('should work on containers', () => {
|
||||
function createTemplate() {
|
||||
container(0, embeddedTemplate, undefined, ['vcref', '']);
|
||||
elementStart(1, 'footer');
|
||||
elementEnd();
|
||||
}
|
||||
|
||||
function updateTemplate() {
|
||||
containerRefreshStart(0);
|
||||
containerRefreshEnd();
|
||||
}
|
||||
|
||||
new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
|
||||
expect(directiveInstance !.vcref.element.nativeElement.textContent).toEqual('container');
|
||||
expect(directiveInstance !.vcref.injector.get(ElementRef).nativeElement.textContent)
|
||||
.toEqual('container');
|
||||
expect(() => directiveInstance !.vcref.parentInjector.get(ElementRef)).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('projection', () => {
|
||||
|
Reference in New Issue
Block a user