我有一個Angular 2應用程序,我已經實現了一個管道來基本檢查一些空值。問題是,當我使用map()
我得到下面的錯誤:使用Angular 2&Typescript的地圖()錯誤
core.umd.js:2838 EXCEPTION: Uncaught (in promise): Error: Error in app/components/performances/performances.component.html:18:10 caused by: Cannot read property 'map' of undefined
TypeError: Cannot read property 'map' of undefined
下面你可以看看我的代碼:
import { Pipe, PipeTransform } from '@angular/core';
import {Performance} from '../common/performance';
@Pipe({
name: 'defaultPerformanceValueIfNull'
})
export class PerformanceCheckValuesPipe implements PipeTransform {
transform(values: Performance[]): any {
let performances = values.map(function(p) {
return Object.assign(p,
{
OneMonthBack: p.OneMonthBack || '-',
ThreeMonthsBack: p.ThreeMonthsBack || '-'
})
});
return performances;
}
}
我認爲的代碼是好的,你可以看看一個例子,我寫在這裏: link
任何想法它與我的代碼? 謝謝!
您是否嘗試過導入地圖運算符。即.....'導入'rxjs/add/operator/map''或導入所有運算符'import'rxjs/Rx';' – Bean0341