1
NgModel沒有在這個組件上工作。我已經導入了FormsModule和東西。其他功能(如* ngIf和角度* ngFor)在其他組件上運行良好。檢查出app.module。Angular 4 NgModel沒有綁定數據
幫助!
我爲此使用了firebase和angularfire2。
我的組件:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { CommonModule } from '@angular/common';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase, FirebaseObjectObservable } from 'angularfire2/database';
import * as firebase from 'firebase/app';
import { Rating } from '../rating';
import 'rxjs/add/operator/SwitchMap';
@Component({
selector: 'app-view-rating',
templateUrl: './view-rating.component.html',
styleUrls: ['./view-rating.component.css']
})
export class ViewRatingComponent implements OnInit {
name: any;
rating: FirebaseObjectObservable<any>;
user: firebase.User;
item: any;
constructor(
private route: ActivatedRoute,
private afAut: AngularFireAuth,
private afDb: AngularFireDatabase) {
this.afAut.authState.subscribe((auth) => {
this.user = auth;
})
}
ngOnInit(): void {
this.name = this.route.snapshot.paramMap.get('item');
this.rating = this.afDb.object(this.user.uid + '/' + this.name);
console.log(this.rating)
}
}
和HTML:
<div class="form-container">
<div *ngIf="rating" >
<input [(ngModel)]="rating.name" name="name" >
</div>
</div>
您是否在瀏覽器控制檯中看到錯誤? – Aravind
@Aravind不,沒有顯示任何東西 –
@Aravind我試過這個沒有成功,但再次嘗試,現在它的工作原理!是一個簡單的錯誤。我是新來的角。非常感謝。 –