【问题标题】:Argument of type 'string' is not assignable to parameter of type '{ id: string; }'\'string\' 类型的参数不能分配给 \'{ id: string; 类型的参数。 }\'
【发布时间】:2022-08-18 23:30:10
【问题描述】:

我在调度中的参数有问题=> 错误:\“\'string\' 类型的参数不可分配给 \'{ id: string; }\' 类型的参数。\”

export class CharacterDetailsComponent implements OnInit {
 id: string | null= \'\';
 characterDetail$!: Observable<DataFromAPI>;

 constructor(
   private router: ActivatedRoute,
   private store$: Store
 ) {}

 ngOnInit(): void {
   this.id = this.router.snapshot.paramMap.get(\'id\');
   this.getCharacterDetail();
 }

 getCharacterDetail() {
   if (!this.id) {
     return;
   }
   this.store$.dispatch(getCharDetailData(this.id));
   this.characterDetail$ = this.store$.select(charDetailsSelector);
 }

}

那么谁知道如何解决这个问题?

    标签: angular typescript frontend ngrx


    【解决方案1】:

    像这样做:

       this.store$.dispatch(getCharDetailData({id: this.id}));
    

    【讨论】:

      【解决方案2】:

      你能改变你的id: 字符串 |空=''编号:任何 |空='';或者 您可以将 dataType 字符串设置在要分派的位置。

      【讨论】:

        猜你喜欢
        • 2021-10-02
        • 2021-10-06
        • 2020-04-15
        • 2021-09-06
        • 1970-01-01
        • 2021-04-27
        • 2021-08-20
        • 2021-09-08
        • 2021-05-17
        相关资源
        最近更新 更多