Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度模型不绑定数据_Angular_Firebase_Angular Ngmodel_Angularfire2 - Fatal编程技术网

Angular 角度模型不绑定数据

Angular 角度模型不绑定数据,angular,firebase,angular-ngmodel,angularfire2,Angular,Firebase,Angular Ngmodel,Angularfire2,NgModel不在此组件上工作。我已经导入了FormsModule和其他东西。其他功能如*ngIf和angled*ngFor在其他组件上运行良好。也可以查看app.module 救命啊 我用的是firebase和angularfire2 我的组成部分: 从'@angular/core'导入{Component,OnInit}; 从“@angular/router”导入{ActivatedRoute,Params}; 从“@angular/common”导入{CommonModule}; 从'a

NgModel不在此组件上工作。我已经导入了FormsModule和其他东西。其他功能如*ngIf和angled*ngFor在其他组件上运行良好。也可以查看app.module

救命啊

我用的是firebase和angularfire2

我的组成部分:

从'@angular/core'导入{Component,OnInit};
从“@angular/router”导入{ActivatedRoute,Params};
从“@angular/common”导入{CommonModule};
从'angularfire2/auth'导入{AngularFireAuth};
从“angularfire2/database”导入{AngularFireDatabase,FirebaseObjectObservable};
从“firebase/app”导入*作为firebase;
从“../Rating”导入{Rating};
导入'rxjs/add/operator/SwitchMap';
@组成部分({
选择器:“应用程序视图评级”,
templateUrl:'./view rating.component.html',
样式URL:['./查看评级.component.css']
})
导出类ViewRatingComponent实现OnInit{
名称:任何;
评级:FirebaseObjectObservable;
用户:firebase.user;
项目:任何;
建造师(
专用路由:激活的路由,
二等兵:AngularFireAuth,
非洲开发银行私人数据库(数据库){
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)
}

}
评级
属于
可观察的类型
您将如何将其用于
ngModel
。您需要订阅它并分配给其他对象,然后将该对象用作
ngModel

声明类型为any且不可观察的对象,如下所示

ratingObject:any;

this.rating = this.afDb.object(this.user.uid + '/' + this.name);
this.rating.subscribe(data =>{
        this.ratingObject = data;
});
然后在HTML中使用,如下所示

<div *ngIf="ratingObject" >
    <input [(ngModel)]="ratingObject.name" name="name" >
</div>

评级
属于
可观察的类型
您将如何将其用于
ngModel
。您需要订阅它并分配给其他对象,然后将该对象用作
ngModel

声明类型为any且不可观察的对象,如下所示

ratingObject:any;

this.rating = this.afDb.object(this.user.uid + '/' + this.name);
this.rating.subscribe(data =>{
        this.ratingObject = data;
});
然后在HTML中使用,如下所示

<div *ngIf="ratingObject" >
    <input [(ngModel)]="ratingObject.name" name="name" >
</div>


浏览器控制台中是否有错误?@Aravind否,控制台不显示nothing@Aravind我已经尝试过,但没有成功,但再次尝试,现在它的工作!这是一个简单的错误。我是新来的。非常感谢。什么地方出错了?请把答案也投上去。你在浏览器控制台中有什么错误吗?@Aravind没有,控制台没有显示nothing@Aravind我已经尝试过,但没有成功,但再次尝试,现在它的工作!这是一个简单的错误。我是新来的。非常感谢你。错在哪里?把答案也投上去。