我在输入上有ngFor
,现在将具有多个输入,我想将这些inpt值绑定到组件,以便一旦添加输入值即可在逻辑中使用,问题是它没有显示输入字段,所以我可以将数据推送到subQuestionsAnswertext
。
app.component.html
<div class="form-group" *ngIf="showSubQuestionsQues">
<div *ngFor="let option of singleQuestion.answerOption">
<div *ngFor="let sub of option.subQuestion">
<div *ngFor="let ques of sub.question">
<label for="subQuestionsInput">{{ques.questionText}}</label>
<input type="subQuestionsInput" class="form-control" *ngIf="((ques.responseFieldIdentifier == DOES LEFT) || (ques.responseFieldIdentifier == NEXT DOSE))" placeholder="quantity" [(ngModel)]="ques.answerText"> </div>
</div>
</div>
</div>
app.component.ts
import {
Component,
OnInit
} from '@angular/core';
import {
ApiService
} from './api.service';
import {
EventService
} from './format-questions/format-questions.service'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent Implement OnInit {
subQuestionsAnswertext: any = [];
constructor(private dataService: ApiService, private eventService: EventService) {}
ngOnInit(e) {
this.subQuestionsAnswertext.push(e.answerText);
}
}
答案 0 :(得分:0)
请您替换输入字段HTML-
原因-当前NEXT DOSE
被视为变量。您需要将其更改为字符串。
<input type="texy" class="form-control" *ngIf="((ques.responseFieldIdentifier == 'DOES LEFT') || (ques.responseFieldIdentifier == 'NEXT DOSE'))" placeholder="quantity" [(ngModel)]="ques.answerText">