Akh*_*mar 5 javascript angular
我正在尝试使用ngStyle为img指定高度,为此我用一些数学运算来计算高度,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时会出现以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
yur*_*zui 10
每个文件:
也许更令人惊讶的是,模板表达式无法引用全局命名空间中的任何内容.他们不能参考窗口或文档.他们无法调用console.log或Math.max.它们仅限于引用表达式上下文的成员.
https://angular.io/docs/ts/latest/guide/template-syntax.html
你可以解决它:
class Component {
myParseInt = parseInt;
}
Run Code Online (Sandbox Code Playgroud)
HTML
[ngStyle]="{'height':(myParseInt (...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1100 次 |
| 最近记录: |