Answer the question
In order to leave comments, you need to log in
Value drops when you re-createEmbeddedView. What's wrong?
I created the ifViewportSize
directive , which, when rendering the test component , should display its template with a value. But the value is not displayed when re-rendering, what is missing?
Template render:
if( size === this._ifViewportSize ) this.viewContainerRef.createEmbeddedView( this.templateRef );
else this.viewContainerRef.clear();
<test *ifViewportSize="'small'" [value]="1"></test>
import { Component, Input, ViewChild } from '@angular/core';
@Component({
selector: 'test',
template: `Value: {{ value }}`,
})
export class TestComponent{
@Input() value: number;
}
Answer the question
In order to leave comments, you need to log in
You need to use useFactory instead of useValue and return the service instance in the function.
providers: [
{
provide: IfViewportSizeService,
useFactory: () => new IfViewportSizeService( config ) }
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question