1 // Copyright (c) 2016, hackbard. All rights reserved. Use of this source code
2 // is governed by a BSD-style license that can be found in the LICENSE file.
6 import 'package:angular2/core.dart';
7 import 'package:angular2/router.dart';
10 import 'product_service.dart';
11 import 'product_category.dart';
12 import 'product_category_service.dart';
14 import 'package:angular2_rbi/directives.dart';
17 selector: 'my-product-details',
18 templateUrl: 'product_detail_component.html',
19 styleUrls: const ['product_detail_component.css'],
20 directives: const [MaterialTextfield,MaterialButton],
21 providers: const [ProductService,ProductCategoryService]
24 class ProductDetailComponent implements OnInit {
25 final ProductService _prodSrv;
26 final ProductCategoryService _prodcatSrv;
27 final RouteParams _routeParams;
29 List<ProductCategory> prodcats;
36 ProductDetailComponent(this._prodSrv,this._prodcatSrv,
42 Future<Null> ngOnInit() async {
43 var id=_routeParams.get('id');
45 prod = await (_prodSrv.getById(id));
46 prodcats = await (_prodcatSrv.getAll());
49 prod_price=prod.price;
50 prod_category=prod.category;
53 Future<Null> updateProduct() async {
55 if(prod.name!=prod_name) {
58 if(prod.price!=prod_price) {
61 if(prod.category!=prod_category) {
65 print('Debug: Updating product '+
66 prod.name+'/'+prod.price.toString()+'/'+
68 prod_name+'/'+prod_price.toString()+'/'+
70 await _prodSrv.updateProd(
73 double.parse(prod_price),
79 Future<Null> deleteProduct(Product prod) async {
80 print('Debug: Deleting product '+prod.name);
81 await _prodSrv.deleteProduct(prod.id);