我无法从findIndex方法访问我的类变量。
My whole class:
import { Component, Input, OnInit } from '@angular/core';
import { History } from '../model/history';
import { SharedService } from "../shared.service";
@Component({
selector: 'app-details',
templateUrl: './details.component.html',
styleUrls: ['./details.component.scss']
})
export class DetailsComponent implements OnInit {
history: History[] = [
{
basic_text: { basic_text: 'text_1' },
summary: { summary: 'summary_1' },
tager: { tag_algorytm: true, tag_text: "tag_1" }
},
{
basic_text: { basic_text: 'text_2' },
summary: { summary: 'summary_2' },
tager: { tag_algorytm: false, tag_text: "tag_2" }
}
];
basic_text: String = "Tekst podstawowy";
summary: String = "Streszczenie";
rating: String = "Ocenione zdania";
chosedText: string;
asd: string = 'asdad';
constructor(private sharedService: SharedService) { }
ngOnInit() {
this.sharedService.sharedMessage.subscribe(chosedText => this.chosedText = chosedText)
}
textFilter(h: History[]) {
let result: History[] = [];
var param = this.chosedText;
var foundIndex = h.findIndex(this.isEqualToSelectedText, param);
result.push(h[foundIndex])
return result;
}
// The function was moved out
private isEqualToSelectedText(element: History) {
return element.basic_text.basic_text === this.chosedText;
}
}
但如果我这样做
var x= h.findIndex(isEqualToSelectedText, 'text_1');
一切正常。我尝试从 isEqualToSelectedText 函数访问我的类 varialb 。但我总是遇到这个错误。在findIndex运行期间,单词“this”应等于“text_1”。你能帮助我吗?
慕容708150
慕斯王
相关分类