Skip to content

Commit 8742174

Browse files
committed
move ngOnInit
1 parent 628adcc commit 8742174

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

src/AspnetRun.Web/src/app/views/category/category-list/category-list.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export class CategoryListComponent {
1717
}
1818

1919
getCategories() {
20-
this.dataService.getCategories()
21-
.subscribe((categories: ICategory[]) => {
20+
this.dataService.getCategories().subscribe((categories: ICategory[]) => {
2221
this.categories = categories;
2322
});
2423
}

src/AspnetRun.Web/src/app/views/product/product-detail/product-detail.component.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ export class ProductDetailComponent implements OnInit {
1717
category: { id: null }
1818
};
1919

20-
constructor(private dataService: ProductDataService, private router: Router, private route: ActivatedRoute) {
21-
route.params.subscribe(val => {
20+
constructor(private dataService: ProductDataService, private router: Router, private route: ActivatedRoute) {
21+
}
22+
23+
ngOnInit() {
24+
this.route.params.subscribe(val => {
2225
const id = +this.route.snapshot.paramMap.get('id');
2326

2427
if (id !== undefined && id != null && id !== 0) {
2528
this.dataService.getProductById(id).subscribe((product: IProduct) => {
26-
if (product != null) {
27-
this.product = product;
28-
}
29-
else {
30-
this.router.navigate(['/']);
31-
}
29+
if (product != null) {
30+
this.product = product;
31+
}
32+
else {
33+
this.router.navigate(['/']);
34+
}
3235
});
3336
}
3437
else {
@@ -37,9 +40,6 @@ export class ProductDetailComponent implements OnInit {
3740
});
3841
}
3942

40-
ngOnInit() {
41-
}
42-
4343
close() {
4444
this.router.navigate(['/product/product-list']);
4545
}

src/AspnetRun.Web/src/app/views/product/product-edit/product-edit.component.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ export class ProductEditComponent implements OnInit {
2222
private categoryDataService: CategoryDataService,
2323
private formBuilder: FormBuilder,
2424
private router: Router,
25-
private route: ActivatedRoute) {
26-
route.params.subscribe(val => {
25+
private route: ActivatedRoute) {
26+
}
27+
28+
ngOnInit() {
29+
30+
this.route.params.subscribe(val => {
2731
this.initializeForm();
2832

2933
const id = +this.route.snapshot.paramMap.get('id');
@@ -55,9 +59,7 @@ export class ProductEditComponent implements OnInit {
5559
});
5660
}
5761
});
58-
}
5962

60-
ngOnInit() {
6163
}
6264

6365
initializeForm() {

src/AspnetRun.Web/src/app/views/product/product-list/product-list.component.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export class ProductListComponent {
1919
}
2020

2121
getProducts() {
22-
this.dataService.getProductsByName(this.productName).subscribe((products: IProduct[]) => {
23-
this.products = products;
24-
});
22+
this.dataService.getProductsByName(this.productName)
23+
.subscribe((products: IProduct[]) => {
24+
this.products = products;
25+
});
2526
}
2627
}

0 commit comments

Comments
 (0)