나는 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