Hello I have a little problem passing data from a parent Component to a child component controller.
Thats the markup code of my parent Component parent.component.html
<element [mydata]="Value"></element>
With this I set mydata with an value.
I set this value using @Input in my child controller
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'element',
templateUrl: './element.component.html',
styleUrls: ['./element.component.scss'],
})
export class ElementComponent implements OnInit {
@Input() public mydata:string;
ngOnInit() {
console.log(this.mydata);
}
}
I get an undefined in the console, but why?
Valuegets populated from Ajax?<element [mydata]="value">{{value}}</element>but how can I use this variable in the constructor?valueinside constructor.. you should use lifecycle event...