Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 未捕获错误:Can';是否解析ProductListComponent的所有参数?_Typescript_Service_Angular6 - Fatal编程技术网

Typescript 未捕获错误:Can';是否解析ProductListComponent的所有参数?

Typescript 未捕获错误:Can';是否解析ProductListComponent的所有参数?,typescript,service,angular6,Typescript,Service,Angular6,我正在开发一个Angular 6应用程序。我试图将服务注入到我的组件中,当我这样做时,我遇到了以下错误 未捕获错误:无法解析ProductListComponent:(?)的所有参数。 错误是非特定的,因此我无法跟踪导致此代码的行。我的IDE中没有错误。我做错了什么 //产品列表组件 进口{ 组成部分, 奥尼特 }从“@angular/core”开始; 进口{ i产品 }来自“./产品”; 进口{ 产品服务 }来自“./产品.服务”; @组成部分({ 选择器:“pm产品”, templateU

我正在开发一个Angular 6应用程序。我试图将服务注入到我的组件中,当我这样做时,我遇到了以下错误 未捕获错误:无法解析ProductListComponent:(?)的所有参数。 错误是非特定的,因此我无法跟踪导致此代码的行。我的IDE中没有错误。我做错了什么

//产品列表组件
进口{
组成部分,
奥尼特
}从“@angular/core”开始;
进口{
i产品
}来自“./产品”;
进口{
产品服务
}来自“./产品.服务”;
@组成部分({
选择器:“pm产品”,
templateUrl:'./product list.component.html',
样式URL:['./product list.component.css']
})
导出类ProductListComponent实现OnInit{
pageTitle:字符串='产品列表';
图像宽度:数字=50;
imageMargin:数字=2;
showImage:boolean=true;
_listFilter:string='';
获取listFilter():字符串{
返回此项。\u listFilter;
}
设置listFilter(值:字符串){
这是。_listFilter=值;
this.filteredProducts=this.listFilter?this.performFilter(this.listFilter):this.products;
}
filteredProducts:IPProduct[];
产品:IPProduct[]=[];
构造函数(私有产品服务:产品服务){
this.listFilter='cart';
}
OnRatingClicked(消息:字符串):无效{
this.pageTitle=`产品列表:${message}`;
}
performFilter(filterBy:string):IPProduct[]{
filterBy=filterBy.toLocaleLowerCase();
返回此.products.filter((产品:IPProduct)=>
product.productName.toLocaleLowerCase().indexOf(filterBy)!=-1);
}
toggleImage():void{
this.showImage=!this.showImage;
}
ngOnInit():void{
console.log('OnInit');
this.filteredProducts=this.products;
this.products=this.productService.getProducts();
}
}
//产品服务
进口{
注射的
}从“@angular/core”开始;
进口{
i产品
}来自“./产品”;
@注射的({
providedIn:'根'
});
出口类产品服务{
getProducts():IPProduct[]{
返回[{
“productId”:1,
“产品名称”:“叶耙”,
“产品代码”:“GDN-0011”,
“发布日期”:“2016年3月19日”,
“说明”:“48英寸木柄叶耙”,
“价格”:19.95,
“主演”:3.2,
“imageUrl”:https://openclipart.org/image/300px/svg_to_png/26215/Anonymous_Leaf_Rake.png"
},
{
“productId”:2,
“产品名称”:“花园车”,
“产品代码”:“GDN-0023”,
“发布日期”:“2016年3月18日”,
“说明”:“容量为15加仑的滚动花园车”,
“价格”:32.99,
“主演”:4.2,
“imageUrl”:https://openclipart.org/image/300px/svg_to_png/58471/garden_cart.png"
},
{
“productId”:5,
“产品名称”:“锤子”,
“产品代码”:“TBX-0048”,
“发布日期”:“2016年5月21日”,
“说明”:“弯爪钢锤”,
“价格”:8.9,
“主演”:4.8,
“imageUrl”:https://openclipart.org/image/300px/svg_to_png/73/rejon_Hammer.png"
},
{
“productId”:8,
“产品名称”:“Saw”,
“产品代码”:“TBX-0022”,
“发布日期”:“2016年5月15日”,
“说明”:“15英寸钢刃手锯”,
“价格”:11.55,
“主演”:3.7,
“imageUrl”:https://openclipart.org/image/300px/svg_to_png/27070/egore911_saw.png"
},
{
“productId”:10,
“产品名称”:“视频游戏控制器”,
“产品代码”:“GMG-0042”,
“发布日期”:“2015年10月15日”,
“说明”:“标准双按钮视频游戏控制器”,
“价格”:35.95,
“主演”:4.6,
“imageUrl”:https://openclipart.org/image/300px/svg_to_png/120337/xbox-controller_01.png"
}
]
}
}
//产品界面
导出接口IPProduct{
productId:编号;
产品名称:字符串;
产品代码:字符串;
releaseDate:字符串;
描述:字符串;
价格:数量;
星号:数字;
imageUrl:字符串;

}
您的
@Injectable()
装饰程序在大小写方面可能有输入错误。而不是:

@injectable({
  providedIn: 'root'
});
export class ProductService { ... }
尝试以下操作:

@Injectable({
  providedIn: 'root'
})
export class ProductService { ... }
@Injectable()
需要大写字母“I”来匹配从“@angular/core”导入的符号
import{Injectable}。您的示例在
@Injectable({})
的右括号后有一个小写“i”和一个分号


希望这有帮助

捕捉得好,但现在我在控制台中出现了这个错误。”错误:StaticInjectorError(AppModule)[ProductListComponent->ProductService]:'AppComponent.html:6没问题,很高兴提供帮助!关于新错误,创建一个新问题可能会更好,但您是否将此
ProductService
添加到一些
NgModule
中的
提供者列表中:[]
?使用
@Injectable()
providedIn
标志可能会导致冲突,因为它在
提供程序中不需要:[]
。我删除了分号,并解决了问题。我不太清楚为什么添加分号会导致这个错误。有什么想法吗?只需添加不带分号的字符。对于存在的linting工具(如TSLint),使用分号进行编译时不能没有错误。分号打断装饰符的内在原因我无法理解。