请帮忙。
我在我的应用程序上得到了这行代码,这里输入的值来自 firebase 数据库。这在我运行应用程序时显示的值有效。我的问题是当我 console.log(attendance.studentName) 时。它没有得到价值。它是 null 或 {}。
HTML
<ion-item *ngFor="let student of studentList$ | async">
<!-- problem here, ngModel -->
<ion-input [ngModel]="attendance.studentName" [value]="student.name"></ion-input>
<ion-select item-end [ngModel]="attendance.status">
<ion-option value="Present">Present</ion-option>
<ion-option value="Absent">Absent</ion-option>
<ion-option value="Late">Late</ion-option>
</ion-select>
</ion-item>
TS
attendance = {} as Attendance
export class CheckAttendancePage {
studentList$: Observable<Student[]>
attendance = {} as Attendance
constructor(private afDatabase: AngularFireDatabase, private studentsList: StudentListService, private attendanceList: AttendanceListService, public navCtrl: NavController, public navParams: NavParams) {
this.studentList$ = this.studentsList
.getStudentList()
.snapshotChanges()
.map(
changes => {
return changes.map(c => ({
key: c.payload.key, ...c.payload.val()
}))
}
)
}
addAttendance(attendance: Attendance){
console.log(attendance)
}
模型
export interface Attendance {
key?: string;
studentName: string;
status: string;
}
服务
@Injectable()
export class AttendanceListService {
private attendanceListRef = this.db.list<Attendance>('attendance')
private studentListRef = this.db.list<Student>('students-list')
constructor(private db: AngularFireDatabase){}
getStudentsList() {
return this.studentListRef;
}
请帮忙