0
既然我已经创建并添加自定义过滤器管的一个数组我得到这个例外,当视图加载:不能与自定义过滤器管读取属性“0”的未定义
TesttypesListComponent - inline template:35:14 caused by: Cannot read property '0' of undefined
这必须有一些待办事项我猜测我如何加载数据。
在我添加管道数据加载工作!
我可以在管道中放置一个断点,但由于错误它永远不会打到里面。
任何人有一个想法,我做错了我的第一个管道?
PIPE
进口{管,PipeTransform}从 '@角/芯';
@Pipe({
name: 'TestTypePipe'
})
export class TestTypePipe implements PipeTransform {
transform(testTypes, args?) {
let [currentSubject, currentSchoolclass] = args;
if (!currentSubject || !currentSchoolclass) {
return [];
}
else {
return testTypes.filter(s => {
return s.subjectId == currentSubject.subjectId && s.schoolclassId == currentSchoolclass.schoolclassId;
});
}
}
}
HTML
<tbody>
<tr *ngFor="let t of testTypes | TestTypePipe:currentSubject:currentSchoolclass; let i = index">
<template [ngTemplateOutlet]="getTemplate(t)" [ngOutletContext]="{ $implicit: t, index: i }"></template>
</tr>
</tbody>
COMPONENT
currentSubject: Subject;
currentSchoolclass: Schoolclass;
ngOnInit() {
this.route.params.subscribe(params => { this.schoolyearId = parseInt(params['id']); });
this.testService.getTestTypes(this.schoolyearId).subscribe(data => {
this.schoolclasses = data.schoolclasses.map(m => new Schoolclass(m));
this.subjects = data.subjects.map(m => new Subject(m));
for (let t of data.testTypes) {
t.viewMode = ViewMode.Displaying;
let testType = new AssignedTestType(t);
this.testTypes.push(testType)
}
}
); }
如果删除参数':currentSubject:currentSchoolclass',是否会调用管道? –
然后我得到这个错误:无法在http:// localhost:4200/main.bundle上读取TestTypePipe.transform(http:// localhost:4200/main.bundle.js:72680:34)处未定义的属性'0' .js:20150:22 at =>似乎我会取消和console.log明天的一些东西,找到未定义的... – Pascal
嗡嗡声,正确的,这是因为let行内部转换,它试图从数组中读取参数 –