Running Angular2 framework and I'm getting the mentioned above error message
Error in ./AppComponent class AppComponent - inline template:2:8 caused by: No provider for ProductService!
Although the service is defined in the providers array of the app.component.ts file, which is the relevant file for the service to be referenced (see below text). The error triggers at core.umd.js file:
import { ProductService } from './products/product.service';
@Component({
selector: 'pm-app',
template: ``,
providers:[ ProductService ]
})
product.Service code:
import {Injectable} from '@angular/core';
import { IProduct } from './product';
@Injectable()
export class ProductService
{
getProducts(): IProduct[]
{
return []
}
}
product-list.component:
@Component ({
selector: 'pm-products',
moduleId: module.id,
templateUrl: 'product-list.Component.html',
styleUrls: ['product-list.Component.css']
})
export class ProductListComponent implements OnInit
{
products: IProduct[];
constructor(private _productService: ProductService){}
ngOnInit(): void{
this.products = this._productService.getProducts();
}
}
and the relevant code in the product-list.component.html:
<table class='table' *ngIf="products && products.length">