Class Interface function definition - TypeError: Object doesn't support property or method

前端 未结 3 694
生来不讨喜
生来不讨喜 2020-12-12 07:08

I\'ve written a construct similar to the following in an Angular app (this has been greatly simplified to demonstrate the issue). What would prevent the filte

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 07:50

    As I think filter is reserved keyword. So that angular trying to implement filter function on type Object. filter can be used only for Array . try using different name for the function.

    If this is not the case. Maybe the service data item should come as Object instead of TTem instance.We can get the class methods only on its instances. Can you try creating new instance as follows

    this.filteredData = this.service.data.value.slice().filter(
    (item: TItem) => {
                // Object doesn't support property or method 'filter'
                let instance: TItem = new TItem();
                Object.assign(instance, item);
                const searchStr = instance.filter().toLowerCase();
                return searchStr.indexOf(this.filter.toLowerCase()) !==-1;
            });
    

提交回复
热议问题