I want to set the child component property from parent component
parent.component.html
<div>
<child-detail #myCarousel [childList]="detail.List" ></child-detail>
</div>
parent.component.ts
@Component({
selector: "parent",
templateUrl: "./parent.component.html",
})
export class AppComponent {
public detail; // it is of JSON type
}
child.component.ts
@component({
selector:'child-detail',
templateUrl: './child.component.html'
})
export class ChildDetailComponent{
@Input() public childList; // that list of array type
}
child.component.html
<div *ngFor = "let list of childList">
<li>{{list}} </li>
</div>
I know i can set this property by @Input() binding , but this will set only at the time of initializing of the component , I want to set it programmaticaly in intermediate at some point .
I know I can access this child property in parent using
@ViewChild(ChildDetailComponent) childDetailComponent: ChildDetailComponent;
console.log(this.childDetailComponent.childList);
But I want to set it programatically at any event of parent.
inputproperties and populate that input property on an event on parent?ngOnChanges()hookchildListchange in the parent component the value of the childList in the childComponent will also be updated but if you went to change the value ofchildListin the parent component when the value ofchildListchange in the child component you can use set method for thechildListInput// that list of array type, don't you properly declare the type of the variable?