Guest User

Untitled

a guest
Nov 23rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. export class ProductService {
  2. productRef: AngularFireObject<any>;
  3. product: Observable<any>;
  4.  
  5. constructor( private db: AngularFireDatabase ) { }
  6. getOne( productId ) {
  7. this.productRef = this.db.object('/products' + productId);
  8. return this.product = this.productRef.snapshotChanges();
  9. }
  10. }
  11.  
  12. export class ProductFormComponent implements OnInit {
  13. categories$;
  14. product: any;
  15.  
  16. constructor(
  17. private router: Router,
  18. private route: ActivatedRoute,
  19. private categoriesService: CategoryService,
  20. private productService: ProductService
  21. ) { }
  22.  
  23. ngOnInit() {
  24. this.categories$ = this.categoriesService.getCategories();
  25. const id = this.route.snapshot.paramMap.get('id');
  26. if ( id ) {
  27. this.productService.getOne( id ).take( 1 ).subscribe(
  28. p => this.product = p
  29. );
  30. }
  31. }
  32. }
  33.  
  34. <form #f="ngForm" (ngSubmit)="save(f.value)" class="products">
  35. <div class="form-group"><label for="title">Title</label>
  36. <input #title="ngModel" [(ngModel)]="product.???.title" name="title" type="text" class="form-control">
  37. </div>
  38. <button class="btn btn-primary">Save</button>
  39. </form>
  40.  
  41. { "payload": { "category": "africa", "imageUrl": "image 01", "price": 12, "title": "test04" }, "type": "value", "prevKey": null, "key": "-KzWO7MPXevJSgLEdKoT" }
Add Comment
Please, Sign In to add comment