2017-01-10 7 views
5

मैं एक माता पिता के घटक से RouteParams के साथ-साथ बच्चे मार्गोंAngular2 मार्ग मानकों सक्रिय हो और माता पिता के मानकों

export const routes: Routes = [ 
    { path: '', redirectTo: 'list', pathMatch: 'full' }, 
    { path: 'list', component: UsersComponent }, 
    { 
     path: ':id', component: UserDetailComponent, 
     children: [ 
      // { path: '', redirectTo: 'overview', pathMatch: 'full' }, 
      { path: 'overview', component: UserInfoComponent }, 
      { path: 'specs/:id', component: UserProfileComponent } 
     ] 
    } 
]; 

घटक

export class UserDetailComponent implements OnInit { 

constructor(private route: ActivatedRoute) { } 
    ngOnInit() { 
    this.route.parent.params.subscribe((c) => { 
     console.log(c['id']); 
    }); 
    this.route.params.subscribe(params => { 
     console.log(params['id']); 
    }); 
} 
} 

में कैसे मिलता है लेकिन मैं हमेशा अपरिभाषित जब हो रही है मेरी मार्ग सक्रिय हो रहा है। कृपया इस समस्या को हल करने में मदद करें?

अग्रिम धन्यवाद।

+0

आप एक समाधान मिल गया है करने के लिए इस अनुकूलित करने के लिए सक्षम हो जाएगा? मुझे एक ही समस्या है। – brians69

+0

अभी तक समाधान की तलाश नहीं है –

+2

मेरे लिए, मुझे एहसास हुआ कि मैं 'राउटर-आउटलेट 'के बाहर एक घटक में' सक्रिय मार्ग 'को बुला रहा था। यही कारण है कि मैं 'अपरिभाषित 'हो रहा था। घटक को 'राउटर-आउटलेट' के अंदर ले जाने से मेरी समस्या हल हो गई। – brians69

उत्तर

1

यहाँ एक सरल उदाहरण कैसे .ts में पैरामीटर का मान प्राप्त करने के लिए है, उसके बाद आप अपने मामले

import { ActivatedRoute } from '@angular/router'; 

    constructor(private route: ActivatedRoute) { 
     const taskId: string = route.snapshot.params["taskId"]; 
     console.log("this is taskId value = "+ taskId); 
    } 
संबंधित मुद्दे