2016-10-05 43 views
5

मैं एक img ngStyle उपयोग करने के लिए ऊंचाई निर्दिष्ट करने की कोशिश कर रहा हूँ नहीं है और कुछ गणित आपरेशन के साथ है कि मैं कर रहा हूँ की गणना ऊंचाई के लिए इस प्रकार है:लेखन त्रुटि: self.parent.parent.context.parseInt एक समारोह

<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) 

उत्तर

9

प्रति प्रलेखन:

Perhaps more surprising, template expressions cannot refer to anything in the global namespace. They can’t refer to window or document. They can’t call console.log or Math.max. They are restricted to referencing members of the expression context.

https://angular.io/docs/ts/latest/guide/template-syntax.html

आप इसे हल करने के कर सकते हैं:

class Component { 
    myParseInt = parseInt; 
} 

एचटीएमएल

[ngStyle]="{'height':(myParseInt (... 
संबंधित मुद्दे