Well, it works with "input properties", which means that with those passed in this format: @Input () myVariable: string;
I did it fine when this input value is a string, number, or boolean, but with objects I still don't understand what is going on.
So, in the "AppComponent" (.html) template, there might be something like this:
<input type="text" [(ngModel)]="name"> // name is a string property of the AppComponent <app-test [myVal]="name"></app-test>
And the βtest componentβ might look like this:
import {Component, Input } from '@angular/core'; @Component({ selector: 'app-test', template: ` <div> TEST COMPONENT {{myVal}}</div> `, styles: [] }) export class TestComponent { constructor() { } ngOnChanges(changeRecord: SimpleChanges) { console.log('It works!'); if(typeof changeRecord.myVal !== 'undefined){ console.log('myVal = ', changeRecord.myVal.currentValue); } } @Input() myVal: string; }
Greetings.
Mario medrano medrano
source share