Теперь я передаю значение от дочернего к родительскому, когда нажимаю кнопку «Отправить», как передать тот же массив, дочерний инициализирован, я пытался с помощью «ngAfterViewInit», но не сработало. Любая рекомендация здесь.
child
@Component({
selector: 'app-child',
templateUrl: './child.component.html'
})
export class ChildComponent {
cars = ["Saab", "Volvo", "BMW", "BMW", 'Saab'];
@Output() msEvent = new EventEmitter();
constructor() {}
send() {
this.msEvent.emit(this.cars);
}
// ngAfterViewInit() {
// this.msEvent.emit(this.cars);
// }
}
}
child.component.html : <button (click) = 'send()' class="button">send</button>
----------------------------------------
parent
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
cars:any[];
constructor() {
}
rece($event) {
this.cars = $event;
}
}
app.component.html : <app-child (msEvent) = 'rece($event)' [employees] = 'employees'></app-child>