// Copyright (c) 2016, hackbard. All rights reserved. Use of this source code // is governed by a BSD-style license that can be found in the LICENSE file. import 'dart:async'; import 'package:angular2/core.dart'; import 'package:angular2/router.dart'; import 'product_category.dart'; import 'product_category_service.dart'; import 'package:angular2_rbi/directives.dart'; @Component( selector: 'my-product-categories', templateUrl: 'product_category_component.html', styleUrls: const ['product_category_component.css'], directives: const [MaterialTextfield,MaterialButton], providers: const [ProductCategoryService] ) class ProductCategoryComponent implements OnInit { List product_categories; ProductCategory selected_prod_category; String new_prod_category_name; String new_prod_category_id; final ProductCategoryService _prodcatSrv; final Router _router; var docreate=false; ProductCategoryComponent(this._prodcatSrv,this._router); Future getProductCategories() async { product_categories = await _prodcatSrv.getAll(); } Future createProductCategory() async { await _prodcatSrv.createProdCategory( new_prod_category_name, new_prod_category_id ); } void ngOnInit() { getProductCategories(); } void checkInput() { if(new_prod_category_name=='' || new_prod_category_id=='') { docreate=false; } else { docreate=true; for(var cat in product_categories) { if(cat.id==new_prod_category_id) { docreate=false; break; } } } } choose(ProductCategory pt) { selected_prod_category=pt; goto_products(pt); } Future goto_products(ProductCategory pt) => _router.navigate([ 'Products', {'id': pt.id.toString()} ]); }