Closed jacobmcgowan closed 4 years ago
First of all, I like to especially thank you Allen for this library it's great, you did a great thing. Also thank you Jacob for the fix and the helpful comments. I have tried all of the suggestions but I'm still not able to generate the spec file using Karma. I have tried adding the args ' -c ngentest.config.js ' as well as ' --framework=Karma ' Which I specified 'Karma' for the framework. Any suggestions would greatly be appreciated!
@ajosslyn plz be more specific by providing your .ts file
Thanks for the response!
import { Component, OnInit } from '@angular/core';
import { ProductService } from 'src/app/services/product.service';
import { Product } from 'src/app/common/product';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-product-list',
templateUrl: './product-list-grid.component.html',
styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit {
products: Product[];
currentCategoryId: number;
searchMode: boolean;
constructor(private productService: ProductService,
private route: ActivatedRoute) { }
ngOnInit() {
this.route.paramMap.subscribe(() => {
this.listProducts();
});
}
listProducts() {
this.searchMode = this.route.snapshot.paramMap.has('keyword');
if (this.searchMode) {
this.handleSearchProducts();
}
else {
this.handleListProducts();
}
}
handleSearchProducts() {
const theKeyword: string = this.route.snapshot.paramMap.get('keyword');
this.productService.searchProducts(theKeyword).subscribe(
data => {
this.products = data;
}
)
}
handleListProducts() {
const hasCategoryId: boolean = this.route.snapshot.paramMap.has('id');
if (hasCategoryId) {
this.currentCategoryId = +this.route.snapshot.paramMap.get('id');
}
else {
this.currentCategoryId = 1;
}
this.productService.getProductList(this.currentCategoryId).subscribe(
data => {
this.products = data;
}
)
}
}
Resolves #37 and resolves #38.