Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class ProductService {
- productRef: AngularFireObject<any>;
- product: Observable<any>;
- constructor( private db: AngularFireDatabase ) { }
- getOne( productId ) {
- this.productRef = this.db.object('/products' + productId);
- return this.product = this.productRef.snapshotChanges();
- }
- }
- export class ProductFormComponent implements OnInit {
- categories$;
- product: any;
- constructor(
- private router: Router,
- private route: ActivatedRoute,
- private categoriesService: CategoryService,
- private productService: ProductService
- ) { }
- ngOnInit() {
- this.categories$ = this.categoriesService.getCategories();
- const id = this.route.snapshot.paramMap.get('id');
- if ( id ) {
- this.productService.getOne( id ).take( 1 ).subscribe(
- p => this.product = p
- );
- }
- }
- }
- <form #f="ngForm" (ngSubmit)="save(f.value)" class="products">
- <div class="form-group"><label for="title">Title</label>
- <input #title="ngModel" [(ngModel)]="product.???.title" name="title" type="text" class="form-control">
- </div>
- <button class="btn btn-primary">Save</button>
- </form>
- { "payload": { "category": "africa", "imageUrl": "image 01", "price": 12, "title": "test04" }, "type": "value", "prevKey": null, "key": "-KzWO7MPXevJSgLEdKoT" }
Add Comment
Please, Sign In to add comment