আমি যতদূর জানি, 2 টি স্ট্যান্ডার্ড উপায় রয়েছে যে আপনি এটি করতে পারেন।
1. @ ইনপুট
যখনই পিতামাতার ডেটা পরিবর্তন হয়, শিশুটিকে এনজিওনচেনজ পদ্ধতিতে এই সম্পর্কে অবহিত করা হয়। শিশু এটিতে অভিনয় করতে পারে। এটি একটি সন্তানের সাথে যোগাযোগের মানক উপায় way
Parent-Component
public inputToChild: Object;
Parent-HTML
<child [data]="inputToChild"> </child>
Child-Component: @Input() data;
ngOnChanges(changes: { [property: string]: SimpleChange }){
// Extract changes to the input property by its name
let change: SimpleChange = changes['data'];
// Whenever the data in the parent changes, this method gets triggered. You
// can act on the changes here. You will have both the previous value and the
// current value here.
}
- ভাগ করা পরিষেবা ধারণা
একটি পরিষেবা তৈরি করা এবং ভাগ করা পরিষেবাতে একটি পর্যবেক্ষণযোগ্য ব্যবহার করা। শিশু এটিতে সাবস্ক্রাইব করে এবং যখনই কোনও পরিবর্তন আসবে তখন শিশুকে অবহিত করা হবে। এটিও একটি জনপ্রিয় পদ্ধতি। আপনি যখন ইনপুট হিসাবে পাস করেন এমন ডেটা ব্যতীত অন্য কিছু প্রেরণ করতে চান, এটি ব্যবহার করা যেতে পারে।
SharedService
subject: Subject<Object>;
Parent-Component
constructor(sharedService: SharedService)
this.sharedService.subject.next(data);
Child-Component
constructor(sharedService: SharedService)
this.sharedService.subject.subscribe((data)=>{
// Whenever the parent emits using the next method, you can receive the data
in here and act on it.})