编译报错,请问怎样解决?

来源:8-5 本章实战上

斜杠男人

2018-01-20

 webpack: Compiled successfully.
ERROR in src/app/stock/stock-form/stock-form.component.ts(36,9): error TS2322: Type 'Stock[]' is not assignable to type 'Stock'.
src/app/stock/stock-form/stock-form.component.ts(36,9): error TS2322: Type 'Stock[]' is not assignable to type 'Stock'.
  Property 'id' is missing in type 'Stock[]'.
src/app/stock/stock-form/stock-form.component.ts(38,22): error TS2339: Property 'name' does not exist
on type 'Stock[]'.
src/app/stock/stock-form/stock-form.component.ts(39,23): error TS2339: Property 'price' does not exist on type 'Stock[]'.
src/app/stock/stock-form/stock-form.component.ts(40,22): error TS2339: Property 'desc' does not exist
on type 'Stock[]'.
src/app/stock/stock-form/stock-form.component.ts(42,18): error TS2339: Property 'categories' does not
exist on type 'Stock[]'.
src/app/stock/stock-form/stock-form.component.ts(43,18): error TS2339: Property 'categories' does not
exist on type 'Stock[]'.
src/app/stock/stock-form/stock-form.component.ts(44,18): error TS2339: Property 'categories' does not
exist on type 'Stock[]'. 

http://img.mukewang.com/szimg/5a62bbe50001f89213160699.jpg

http://img.mukewang.com/szimg/5a62bbe50001161f11140602.jpg


写回答

1回答

JoJo

2018-01-22

stockService.getStock返回的是Stock[]么?错误是说你不能把一个Stock[]类型的值赋给一个Stock类型的变量

0
1
zhouzhao2016
是Stock【】 这个问题怎么解决啊老师
2018-07-05
共1条回复

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程