我正在尝试使用ngStyle将高度分配给img,为此,我正在使用一些Math操作来计算高度,如下所示:
<div [ngSwitch]="tbNm?tbNm:'itm0'">
<ion-list *ngFor="let vl of scrnshot;let ind=index">
<img *ngSwitchCase="'itm'+ind" alt="Akhilesh" [ngStyle]="{'height':(parseInt(vl.names[0].hitWid.bdHt+(websitTyp(vl._id.origin)?100:0)))+'px','width':(vl.names[0].hitWid.bdWd+'px')}" [src]="vl.names[0].base64">
</ion-list>
</div>
但是当我运行它时,它给出以下错误:
error_handler.js:51 TypeError: self.parent.parent.context.parseInt is not a function
at DebugAppView._View_HomePage9.detectChangesInternal (HomePage.ngfactory.js:1444)
at DebugAppView.AppView.detectChanges (view.js:272)
at DebugAppView.detectChanges (view.js:377)
at DebugAppView.AppView.detectContentChildrenChanges (view.js:290)
at DebugAppView._View_HomePage8.detectChangesInternal (HomePage.ngfactory.js:1407)
at DebugAppView.AppView.detectChanges (view.js:272)
at DebugAppView.detectChanges (view.js:377)
at DebugAppView.AppView.detectContentChildrenChanges (view.js:290)
at DebugAppView._View_HomePage0.detectChangesInternal (HomePage.ngfactory.js:270)
at DebugAppView.AppView.detectChanges (view.js:272)
每个文档:
也许更令人惊讶的是,模板表达式无法引用全局名称空间中的任何内容。他们不能引用窗口或文档。他们无法调用console.log或Math.max。它们仅限于引用表达式上下文的成员。
https://angular.io/docs/ts/latest/guide/template-syntax.html
您可以像这样解决它:
class Component {
myParseInt = parseInt;
}
html
[ngStyle]="{'height':(myParseInt (...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句