2016-11-26 15 views
0

のパラメータに割り当てていない私は、角2で働いていると私は奇妙なエラーがあります:エラーTS2345:型の引数「オブジェクトが」タイプ

error TS2345: Argument of type 'Object' is not assignable to parameter of type 

を、私はラインを命じることは、これを表示されます。

[0] app/category-details.component.ts(40,39): error TS2345: Argument of type 'Object' is not assignable to parameter of type '{ CategoryID: number; }'. 
[0] Property 'CategoryID' is missing in type 'Object'. 
[0] app/category-details.component.ts(45,39): error TS2345: Argument of type 'Object' is not assignable to parameter of type '{ CategoryID: number; }'. 

これはコードです:

export class CategoryDetailComponent implements OnInit { 

    @Input() public category: Object; 

    private view: Observable<GridDataResult>; 
    private skip: number = 0; 

    constructor(private service: ProductsService) { } 

    public ngOnInit(): void { 
     this.view = this.service; 

     this.service.queryForCategory(this.category, { skip: this.skip, take: 5 }); 
    } 

    protected pageChange({ skip, take }: PageChangeEvent): void { 
     this.skip = skip; 
     this.service.queryForCategory(this.category, { skip, take }); 
    } 
} 

それは私のラインで、このエラーを示しています

this.service.queryForCategory(this.category, { skip: this.skip, take: 5 }); 

this.service.queryForCategory(this.category, { skip, take }); 

どうすればこのエラーを解決できますか?

ありがとうございます!

答えて

0

あなたはObjectとして注釈されthis.categoryを渡している間に、第一引数の型{ CategoryID: number; }であることを期待this.service.queryForCategory(this.category, { skip, take });サービス方法。 カテゴリ用のインターフェイスを作成して、queryForCategory@Input() public category: ICategory;の両方を使用しているインターフェイスを作成できます。

// interface.ts 
export interface ICategory { 
    CategoryID: number; 
} 

// service declaration 
queryForCategory(category: ICategory, options) 


// input property annotation 
@Input() public category: ICategory; 
関連する問題