मेरे पास एक मास्टरकंपोनेंट है जो हेडर, पाद लेख, साइडबार इत्यादि लोड करता है। शीर्षलेख पर एक ड्रॉपडाउन होता है जिसका उपयोगकर्ता लॉग इन होने के बाद सेट हो जाता है। मैं चाहता हूं कि हेडर स्थिर हो, भले ही मैं अलग-अलग मार्गों पर नेविगेट करता हूं अलग बाल घटक। इसका मतलब है कि चयनित विकल्प नहीं बदला जाना चाहिए और ड्रॉपडाउन का मूल्य सभी बाल घटक में सुलभ होना चाहिए। ड्रॉपडाउन मूल्य का आदान-प्रदान वर्तमान बाल घटक को अद्यतन/पुनः लोड किया जाना चाहिए।मूल घटक को बदलने पर बच्चे घटक को फिर से लोड करें। Angular2
मुझे इस समस्या से कैसे संपर्क करना चाहिए? मैं घटना-श्रोता प्रकार की कार्यक्षमता चाहता हूं। एक बार मास्टरकंपोनेंट चेंज से मॉडल, वर्तमान बाल घटक को फिर से लोड करें। MasterComponent के चर परिवर्तनीय अद्यतन पर ChildComponent अद्यतन को सुनेंगे और कुछ फ़ंक्शन चलाएंगे या फिर कुछ एपीआई कॉल करेंगे और ChildComponent को फिर से लोड करेंगे।
// routes
const appRoutes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full',
},
{ path: 'login', component: LoginComponent },
{ path: 'logout', component: LogoutComponent },
{
path: '',
component: MasterComponent,
canActivate: [AuthGuard],
children: [
{ path: 'record/create', component: RecordCreateComponent }, // create record for selectedRestaurant in MasterComponent
{ path: 'record/', component: RecordComponent }, // shows all record of current selectedRestaurant in MasterComponent
{ path: 'record/:id/update', component:RecordUpdateComponent }, // show form to edit record having id
{ path: 'record/:id', component: RecordComponent }, // show record details having id
]
},
{ path: '**', redirectTo: 'login' }
];
// MasterComponent
@Component({
selector: 'master',
templateUrl: templateUrl,
styleUrls:[styleUrl1]
})
export class MasterComponent implements AfterViewInit, OnInit{
restaurants: Array<Restaurant> = [];
user:User;
selectedRestaurant: Restaurant;
constructor(private router: Router, private storageHelper:StorageHelper){
}
ngAfterViewInit() {
}
ngOnInit(){
this.user = JSON.parse(this.storageHelper.getItem('user'));
this.restaurants = this.user.restaurants;
this.selectedRestaurant = this.restaurants[0];
this.router.navigate(['/record/' + this.selectedRestaurant.id]);
}
onRestaurantChange(){
this.router.navigate(['/record/' + this.selectedRestaurant.id]);
}
createRecord(){
}
}
प्रश्न का विषय गुमराह कर रहा है "मूल घटक को पुनः लोड किए बिना बाल घटक बदलें।" आपको बस अपने राउटर को ठीक से सेट करने की आवश्यकता है। ऐसा लगता है कि यह माता-पिता <-> बच्चों की समस्या नहीं है। – jmachnik
@jmachnik मैं बाल घटक से पैरेंट चर का उपयोग करना चाहता हूं और इसके विपरीत। और अभिभावक घटकों का मूल्य सभी मार्गों पर सुसंगत होना चाहिए। – Kaushal