私はsimleサービスでコンポーネントを作った。 以下の動作を達成したい - サービスのhttp.get要求が完了したら、受け取ったパラメータを別のget要求に使用する。これは角2付き
ただし、Groupservice要求のthis.sections[0].Id
パラメータは未定義であり、現在のものにはセクションパラメータがありません。 data.jsonから受け取ったデータは正しいですが。
コードは(追加輸入)
@Component({
template: require('./content.component.html'),
styles: [require('./content.component.css')],
providers: [SectionService, GroupService]
})
export class ContentComponent {
id: string;
sections: Array<Section>;
groups: Array<Group>
selectedSectionTitle: "";
constructor(private router: Router, private activateRoute: ActivatedRoute, private sectionService: SectionService, private groupService: GroupService) {
this.router.events.subscribe(path => {
this.id = activateRoute.snapshot.params['id'];
});
this.id = activateRoute.snapshot.params['id'];
}
ngOnInit() {
this.sectionService.getSections()
.subscribe((data: Response) => {
this.sections = data.json();
}, err => {
console.error("Error occurred while saving setting", err);
},() => {
this.groupService.getGroups(this.sections[0].Id).subscribe((data: Response) => {
this.groups = data.json();
})
});
}
}
export class Group {
isSelectionComponentOpened: boolean;
isItemEditComponentOpened: boolean;
Id: string;
Title: string;
SectionId: string;
Items: Array<string>
}
export class Section {
Id: string;
Title: string;
}
@Injectable()
export class SectionService {
constructor(private http: Http) { }
// Переделать на Observable
getSections() {
return this.http.get('Section/Get');
}
}
私はこの問題の原因を把握することはできませんです。 お知らせください。
これは角2です。申し訳ありません。 – Greenmachine