Angular 2,使用eval()函数的内联模板中的错误 [英] Angular 2, Error in inline template using eval() function
问题描述
<li *ngFor="let pdfifRecord of pdf.ifRecord;let i=index">
<p>{{eval(pdfifRecord.labelMsg)}}</p>
</li>
我想显示评估结果.
但是出现错误
由于以下原因导致的内联模板错误:self.parent.parent.parent.context.eval不是函数.
Error in inline template caused by: self.parent.parent.parent.context.eval is not a function.
但是在我的.ts文件中也是如此例如:
console.log(eval("GECM_IFL_ATTENTION_NEEDED_ITIQ"));
But the same working in my .ts file
eg:console.log(eval("GECM_IFL_ATTENTION_NEEDED_ITIQ"));
推荐答案
那么您不应该使用 eval
.但是要回答您的问题.它说它不是函数的原因是因为它正在您的类中寻找名为eval的函数.哪个不存在.
Well you shouldn't use eval
. But to answer your question.The reason it says it is not a function is because its looking for a function called eval in your class. Which does not exist.
例如,这将起作用:
@Component({
selector: 'my-component',
template: `<h2>Hello {{eval()}}`
})
export class MyComponent {
public eval() {
let e = eval(2*3);
return e ;
}
}
Plunkr示例:
https://plnkr.co/edit/YZJGPX8pjf9BNbB1F8JJ?p=preview
同样,您不应该使用eval.
Again, You shouldn't use eval.
这篇关于Angular 2,使用eval()函数的内联模板中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!