获取 FirebaseObjectObservable 的子项 - Angularfire2
Get child of FirebaseObjectObservable - Angularfire2
是否可以定位 FirebaseObjectObservable 的子项?
请检查下面的 RcTestAppComponent.save()
(注释行)。
示例来自:https://github.com/angular/angularfire2/blob/master/docs/3-retrieving-data-as-lists.md
import { Component } from '@angular/core';
import { AngularFire, FirebaseObjectObservable } from 'angularfire2';
@Component({
moduleId: module.id,
selector: 'app',
template: `
<h1>{{ item | async | json }}</h1>
<input type="text" #newname placeholder="Name" />
<input type="text" #newsize placeholder="Size" />
<br />
<button (click)="save(newname.value)">Set Name</button>
<button (click)="update(newsize.value)">Update Size</button>
<button (click)="delete()">Delete</button>
`,
})
export class RcTestAppComponent {
item: FirebaseObjectObservable<any>;
constructor(af: AngularFire) {
this.item = af.database.object('/item');
}
save(newName: string) {
this.item.set({ name: newName });
/*
// can I do somethin like this:
let index = 2;
this.item.child(index).set({ name: newName });
// index is a dynamic number;
// when I use .child() on this.item, i receive a error:
// TypeError this.item.child is not a function
*/
}
update(newSize: string) {
this.item.update({ size: newSize });
}
delete() {
this.item.remove();
}
}
谢谢
我设法找到了一个解决方案,以便 set
一个对象到动态路径,使用不同的方法。
export class RcTestAppComponent {
/*
item;
constructor(af: AngularFire) {
this.item = af;
}
*/
constructor(af: AngularFire) {
// cleaner TypeScript approach than the above commented lines :o fftopic
}
save(newName: string) {
let index = 2; // it's a dynamic number
this.af.database.object('/item/' + index).set({ name: newName };
}
是否可以定位 FirebaseObjectObservable 的子项?
请检查下面的 RcTestAppComponent.save()
(注释行)。
示例来自:https://github.com/angular/angularfire2/blob/master/docs/3-retrieving-data-as-lists.md
import { Component } from '@angular/core';
import { AngularFire, FirebaseObjectObservable } from 'angularfire2';
@Component({
moduleId: module.id,
selector: 'app',
template: `
<h1>{{ item | async | json }}</h1>
<input type="text" #newname placeholder="Name" />
<input type="text" #newsize placeholder="Size" />
<br />
<button (click)="save(newname.value)">Set Name</button>
<button (click)="update(newsize.value)">Update Size</button>
<button (click)="delete()">Delete</button>
`,
})
export class RcTestAppComponent {
item: FirebaseObjectObservable<any>;
constructor(af: AngularFire) {
this.item = af.database.object('/item');
}
save(newName: string) {
this.item.set({ name: newName });
/*
// can I do somethin like this:
let index = 2;
this.item.child(index).set({ name: newName });
// index is a dynamic number;
// when I use .child() on this.item, i receive a error:
// TypeError this.item.child is not a function
*/
}
update(newSize: string) {
this.item.update({ size: newSize });
}
delete() {
this.item.remove();
}
}
谢谢
我设法找到了一个解决方案,以便 set
一个对象到动态路径,使用不同的方法。
export class RcTestAppComponent {
/*
item;
constructor(af: AngularFire) {
this.item = af;
}
*/
constructor(af: AngularFire) {
// cleaner TypeScript approach than the above commented lines :o fftopic
}
save(newName: string) {
let index = 2; // it's a dynamic number
this.af.database.object('/item/' + index).set({ name: newName };
}