简体   繁体   English

错误 TS2322:“对象”类型不可分配给“产品”类型

[英]Error TS2322: Type 'Object' is not assignable to type 'Produit'

I am new in angular and since 5 days i am getting " ERROR in src/app/modifier-produit/modifier-produit.component.ts(23,7): error TS2322: Type 'Object' is not assignable to type 'Produit'. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Property 'idProduit' is missing in type 'Object'. " in my IDE console我是 angular 的新手,自从 5 天以来,我收到了“ src/app/modifier-produit/modifier-produit.component.ts(23,7) 中的错误:错误 TS2322:类型“对象”不可分配给类型“产品” '。'Object' 类型可分配给很少的其他类型。您是想改用'any' 类型吗?'Object' 类型中缺少属性 'idProduit'。 ”在我的 IDE 控制台中

Someone could please me to find what i did wrong?有人可以请我找出我做错了什么吗?

Produit model产品型号

export class Produit {
    idProduit:any;
    designationProduit:string='';
    prixAchatProduit:number=0;
    prixVenteProduit:number=0;
}

my ts File我的 ts 文件

@Component({
  selector: 'app-modifier-produit',
  templateUrl: './modifier-produit.component.html',
  styleUrls: ['./modifier-produit.component.css']
})
export class ModifierProduitComponent implements OnInit {

  produit:Produit=new Produit();
  idProduit:number;

  constructor(private service:ProduitService, private router:Router, private activatedRoute:ActivatedRoute) {
    this.idProduit = this.activatedRoute.snapshot.params['idProduit'];
   }

  ngOnInit() {    
    this.service.editOneProduit(this.idProduit).subscribe(data => {
      this.produit=data;
    })
  }
}

添加响应类型

this.service.editOneProduit(this.idProduit).subscribe((data: Produit) => {

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误TS2322:无法将类型“对象”分配给类型“接触”。 角 - error TS2322: Type 'Object' is not assignable to type 'Contact'. Angular 错误TS2322:类型&#39;对象&#39;不能分配给&#39;电影&#39;类型? Angular 7 - error TS2322: Type 'Object' is not assignable to type 'Movie'? Angular 7 错误 TS2322:“数字”类型不可分配给“字符串”类型 - error TS2322: Type 'number' is not assignable to type 'string' 错误TS2322:类型&#39;Observable &lt;{} []&gt;&#39;不能分配给&#39;Observable类型 <Archive[][]> “ - error TS2322: Type 'Observable<{}[]>' is not assignable to type 'Observable<Archive[][]>' 错误 TS2322:键入“字符串 | null' 不可分配给类型 'number' - error TS2322: Type 'string | null' is not assignable to type 'number' Angular:错误TS2322:类型'ItemsResponse'不能赋值为'string []' - Angular: error TS2322: Type 'ItemsResponse' is not assignable to type 'string[]' 错误TS2322:类型&#39;()=&gt;字符串&#39;无法分配给类型&#39;字符串&#39; - error TS2322: Type '() => string' is not assignable to type 'string' 无法将类型“ Post []”分配给类型“可观察” <Post[]> &#39;:错误TS2322 - Type 'Post[]' is not assignable to type 'Observable<Post[]>': error TS2322 错误 TS2322:类型“数字”不可分配给 angular 中的类型“字符串” - error TS2322: Type 'number' is not assignable to type 'string' in angular 错误 TS2322:类型“事件”不可分配给类型“布尔值” - error TS2322: Type 'Event' is not assignable to type 'boolean'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM