I have (angular 6) component and input parameter of TemplateRef<any>
type
class TestComponent {
@Input() tpl: TemplateRef<any>;
...
}
Now I want to create a test and I can't find the way how to create a template in test and set it as an input field.
In my HTML I have template like
<test>
<ng-template #tpl>
<div>OLOLO</div>
</ng-template>
</test>
I need something like this
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
component.template = here I need instance of TemplateRef
Thanks
I didn't got why you are doing it this way, but if you want to access the template in spec file, instead of using input use viewchild
in the component
so use code will be
class TestComponent {
@ViewChild('tpl') public tpl: ElementRef;
...
}
and in spec.ts try this
it('should create', () => {
console.log(component.tpl);
expect(component).toBeTruthy();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With