我是使用angularfire2的新手。 我想使用ionic和angularfire2
创建这个数据库设计-|items
-|itemId
-|user: uid
然而有消息显示
“运行时错误无法设置未定义的属性'userid'”
。请帮我 :( 这是我的代码.. 谢谢
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
export class Item {
merknya: string;
type: string;
year: string;
place: string;
userId : string;
}
@IonicPage()
@Component({
selector: 'page-input-motor',
templateUrl: 'input-motor.html',
})
export class InputMotorPage {
items: FirebaseListObservable<Item[]> = null;
userId: string;
constructor(
private afDatabase: AngularFireDatabase,
private afAuth: AngularFireAuth,
public navCtrl: NavController,
public navParams: NavParams) {
this.afAuth.authState.subscribe(user =>{
if(user) this.userId = user.uid })
}
ionViewDidLoad() {
console.log('ionViewDidLoad InputMotorPage');
}
getItemsList(): FirebaseListObservable<Item[]> {
if (!this.userId) return;
this.items = this.afDatabase.list(`items/`);
return this.items
}
// Create a brand new item
submit(item: Item) {
item.userId = this.userId
this.items.push(item)
}
}
这是我学习angularfire angularfire2
的链接