asked before, but it has not been solved.
https://codeshelper.com/q/1010000014617475?_ea=3684537
where did this request come from?
Request URL: http://localhost:4200/api/products?title=1234&category=-1
which friend can give me some advice?
how should I troubleshoot errors
search(params: ProductSearchParams): Observable<Product[]> {
return this.http.get("/api/products", { search: this.encodeParams(params) }).map(res => res.json());
}
private encodeParams(params: ProductSearchParams) {
return Object.keys(params)
.filter(key => params[key])
.reduce((sum: URLSearchParams, key: string) => {
sum.append(key, params[key]);
return sum;
}, new URLSearchParams());
}
}
1. Click on the page to search and the correct results should be as follows:
2.:
3. The search template is as follows:
<form name="searchForm" role="form" [formGroup]="formModel" (ngSubmit)="onSearch()" novalidate>
<div class="form-group" [class.has-error]="formModel.hasError("minlength", "title")">
<label for="productTitle">:</label>
<input formControlName="title" type="text" id="productTitle" placeholder="" class="form-control">
<span class="help-block" [class.collapse]="!formModel.hasError("minlength", "title")">
3
</span>
</div>
<div class="form-group" [class.has-error]="formModel.hasError("positiveNumber", "price")">
<label for="productPrice">:</label>
<input formControlName="price" type="number" id="productPrice" placeholder="" class="form-control">
<span class="help-block" [class.collapse]="!formModel.hasError("positiveNumber", "price")">
</span>
</div>
<div class="form-group">
<label for="productCategory">:</label>
<select formControlName="category" id="productCategory" class="form-control">
<option value="-1"></option>
<option *ngFor="let category of categories" [value]="category">{{category}}</option>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block"></button>
</div>
</form>
4. The product template is as follows:
<div class="container">
<div class="row">
<div *ngFor="let product of products | async" class="col-lg-4">
<div class="img-thumbnail margin_b">
<img class="card-img-top" [src]="imgUrl" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{product.price}} </h5>
<h5 class="card-title">
<a [routerLink]="["/product", product.id]">{{product.title}}</a>
</h5>
<p class="card-text">{{product.desc}}
<a href="-sharp" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
</div>
</div>