angurlar 6 truyền dữ liệu từ component cha sang component con bằng subject thông qua sevice
-
chào mn !!
có ai biết cách truyền dữ liêu component cha sang cong không ạ ??chaComponent và conComponent cùng thực hiện 1 cú pháp để thay đổi và lấy dữ liệu trong service ?
nhưng:
chaComponent thì thực hiện được
còn conComponent thì không
modalService.service.ts:
export class ModalService {
subject: Subject<any> = new Subject<any>();
observable: Observable<any> = this.subject.asObservable();constructor() { }
}chaComponent.ts:
this.modalService.subject.next([
{ name: 'Harold', age: 35 }
]
);
this.modalService.observable.subscribe(data => console.log(data));conComponent.ts
this.modalService.subject.next([
{ name: 'Harold', age: 35 }
]
);
this.modalService.observable.subscribe(data => console.log(data));