我的 account.service.ts 遇到此错误
帐户类型的参数不能分配给任何类型的参数[]
和即时通讯目前使用角度为6“
这是我的代码account.service.ts
import { Injectable } from '@angular/core';
import { AngularFireList, AngularFireObject, AngularFireDatabase } from 'angularfire2/database';
import { Account } from '../models/Account';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
@Injectable()
export class AccountService {
accounts:AngularFireList<any[]>;
account:Observable<any>;
accountRef:AngularFireObject<any>;
constructor(public af:AngularFireDatabase) {
this.accounts = this.af.list('/users') as AngularFireList<Account[]>;
this.account = this.accounts.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}
getAccounts(){
return this.account;
}
newAccount(account:Account){
this.accounts.push(account); ==> **Error code on account**
}
getAccount(id:string){
this.accountRef = this.af.object('/users/'+id) as AngularFireObject<Account>;
return this.accountRef;
}
updateAccount(id:string, account:Account){
return this.accounts.update(id, account); ==> *Error code on line account*
}
deleteAccount(id:string){
return this.accounts.remove(id);
}
}
我的模型Account.ts
export interface Account{
key?:string;
email?:string;
nama?:string;
fakultas?:string;
jenisKelamin?:string;
}
答案 0 :(得分:0)
您无需将其设置为任何AngularFireList<any[]>;
的任何数组,只需简单地将其设置为AngularFireList<any>;
任何本身都意味着任何类型,例如观测值,整数数组等。