Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 08b79ce

Browse files
dynamic search added
1 parent 8742174 commit 08b79ce

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component,OnInit } from '@angular/core';
22
import { ProductDataService } from 'src/app/core/services/product-data.service';
33
import { ActivatedRoute } from '@angular/router';
44
import { IProduct } from 'src/app/shared/interfaces';
@@ -8,20 +8,33 @@ import { IProduct } from 'src/app/shared/interfaces';
88
templateUrl: './product-list.component.html',
99
styleUrls: ['./product-list.component.css']
1010
})
11-
export class ProductListComponent {
11+
export class ProductListComponent implements OnInit {
12+
1213
products: IProduct[];
13-
productName: string = '';
14+
//productName: string = '';
1415

15-
constructor(private dataService: ProductDataService, route: ActivatedRoute) {
16-
route.params.subscribe(() => {
16+
_productName: string = '';
17+
get productName(): string {
18+
return this._productName;
19+
}
20+
set productName(value: string) {
21+
this._productName = value;
22+
this.getProducts();
23+
}
24+
25+
constructor(private dataService: ProductDataService, private route: ActivatedRoute) {
26+
}
27+
28+
ngOnInit(): void {
29+
this.route.params.subscribe(() => {
1730
this.getProducts();
1831
});
1932
}
2033

2134
getProducts() {
22-
this.dataService.getProductsByName(this.productName)
23-
.subscribe((products: IProduct[]) => {
35+
this.dataService.getProductsByName(this.productName).subscribe((products: IProduct[]) => {
2436
this.products = products;
2537
});
2638
}
39+
2740
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /