Import {injectable} from '@angular/core'; import {Realtimeservice} from ".. /shared"; import {firebaselistobservable} from "Angularfire2"; @Injectable () ExportclassCourseservice {courses$: firebaselistobservable<any>; PublicLastcourse:any; Constructor (PrivateRt:realtimeservice) { This. courses$ =rt.getcourseobs (); This. Getlastcourse (); } addcourse (course) {return This. Courses$.push (Course). Then (Success=Success.key, Err= Console.error ("Err", err)); } removecourse (course) {return This. Courses$.remove (Course). Then (()="OK", Err= Console.error ("Err", err)); } updatecourse (course, updates) {return This. Courses$.update (course, updates). Then (()="OK", Err= Console.error ("Err", err)); } getlastcourse () { This. courses$. Subscribe (Courses= { This. Lastcourse = Courses[courses.length-1] } ) }}
[Angularfire 2] Push, remove, update