@Input
을 통해 하위 구성 요소로 전달되는 데이터가 있습니다. 데이터로 작업하려면 액세스하려고하는 객체가 유형 FirebaseObjectObservable<any>
에 존재하지 않는다는 오류가 발생합니다. 여기"FirebaseObjectObservable 유형에 ... '속성'... '이 (가) 존재하지 않습니다. @Input으로받은 데이터로 작업 할 때 오류가 발생합니다.
는 데이터의 덩어리가 다른 부모 구성 요소에 사용됩니다 그것은이
@Input('busImageQuesI')
questions: FirebaseObjectObservable<any>; // console.logs the questions showing they made it safely to the component.
이 하위 구성 요소로 제공되고있는 아이 컴퍼넌트 내부
"questions" : {
"question01" : {
"id" : "an ID",
"name" : "a name",
"question" : "a question",
"answers" : {
"answer01" : {
"answer" : "some answer",
"id" : "an ID"
},
"answer02" : {
"answer" : "another answer",
"id" : "an ID"
}
}
},
"question02" : {....},
"question03" : {....}
}
어떻게 구성되어 있는지 그리고 그것은 자신의 아이의있다 구성 요소를 호출 할 부모 구성 요소에 따라 채 웁니다. 지금까지 나는 어떤 데이터 집합이 표시되는지 결정하기 위해 if 문을 사용할 것이라고 생각했습니다. 지금까지 내가 내가 부모 구성 요소를 기반으로 원하는 질문을 보내이 일을 해요이
<multiple-choice-radio *ngIf="expbTrigger"></multiple-choice-radio>
<multiple-choice-radio *ngIf="rebbTrigger"></multiple-choice-radio>
<multiple-choice-radio *ngIf="newbTrigger"></multiple-choice-radio>
같은 템플릿의 다른 요소를 전환 할 것을 사용하고이
expbTrigger: boolean = false;
rebbTrigger: boolean = false;
newbTrigger: boolean = false;
ngOnInit() {
var myLocation = window.location.pathname;
if (myLocation.includes('expand')){
this.expbTrigger = true;
} else if (myLocation.includes('recreate')){
this.rebbTrigger = true;
} else if (myLocation.includes('new-business')){
this.newbTrigger = true;
}
console.log(this.expbTrigger, this.rebbTrigger, this.newbTrigger);
}
처럼 보인다 그 중 일부는 독점적 인 것이 아니기 때문에 모든 부분에서 모두 사용되는 것은 아니므로 수동으로 설정하고 *ngIf
을 사용하여 적절한 경우 켜고 끌 수 있습니다.
@Input
에 의해 수신 된 questions
개체에는 3 개의 질문이 있습니다. expbTrigger = true
경우 내가 질문 하나를 사용하려면 내가 질문 내가 생각 3. 사용하려는 2. rebbTrigger = true
경우,이 코드는
questionA: FirebaseObjectObservable<any>;
questionB: FirebaseObjectObservable<any>;
ngOnChanges(){
if(this.expbTrigger = true){
this.questionA = this.questions.question01;
this.questionB = this.questions.question02;
} else if(this.rebbTrigger = true){
this.questionA = this.questions.question03;
this.questionB = null;
}
}
를 작동합니다하지만 난이 오류를
Property 'question01' does not exist on type 'FirebaseObjectObservable<any>'
을 얻고 동일한 말한다 질문 2와 3을 위해. 코드를 주석 처리하고 console.log(questions)
을 실행하면 코드가 기록되고 그 안에있는 모든 질문이 표시됩니다. 나는 그것을 ngAfterViewInit
으로 옮기려고했지만 같은 오류가 발생했습니다. 내가 본 모든 예제는 거의 1 개의 단일 계층 데이터이므로 중첩 된 데이터 본문을 검색하는 것과 관련하여 내가 잘못하고있는 것을 말하기는 어렵습니다. 누구든지 도와 줄 수 있습니까?