I have this component. I want to do something just the first time the @Input
changes. The problem is that the changes.firstChange
is always false (on init and after changed).
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'test',
templateUrl: './t.component.html',
styleUrls: ['./t.component.css']
})
export class TComponent implements OnChanges {
@Input()
myValue: string;
ngOnChanges(changes: SimpleChanges) {
console.log('myValue: ', changes.myValue.isFirstChange()); // always false
console.log('myValue: ', changes);
}
}
For using it, I'm doing:
myValue = of('1').pipe(
delay(2000),
// startWith('2')
)
I also tried:
myValue = '1'
<test [myValue]="myValue | async "></test>
// When using of
As you can see in the images changes.firstChange
is always false, no matter if I pass a string or a new value later.
And this is the output when using the rxjs value:(value changed but never changed firstChange to true
because that haven't previousValue