2016-09-06 25 views
5

में div टैग को अक्षम करने के लिए मैं उस क्रिया के सफल कॉलबैक के बाद div टैग को अक्षम करने का प्रयास कर रहा हूं।कोणीय 2

कृपया मेरी आयन सामग्री

<ion-content padding class="forgot-password"> 
    <div [ngClass]="{active: isOn,disabled: isDisabled}"> 
    <ion-item> 
     <ion-label floating>Email/Mobile</ion-label> 
     <ion-input type="text" [(ngModel)]="loginId"></ion-input> 
    </ion-item> <br><br> 

    <button class="float-right" (click)="generateOTP(!isOn);">Send OTP</button><br><br><br> 
    </div> 
    <br> 

    <div *ngIf="showRePasswd"> 
    <ion-item> 
     <ion-label floating>Enter OTP</ion-label> 
     <ion-input type="text" [(ngModel)]="passwd"></ion-input> 
    </ion-item> <br><br> 

    <button class="float-right" (click)="resetPassword();">Send Password</button> 
    </div> 
</ion-content> 
यहाँ

मेरी .ts फ़ाइल है

export class ForgotPasswordPage { 

    public loginId = ""; 
    public passwd = ""; 

    public showRePasswd = false; 
    isDisabled = false; 
    isOn = false; 

    constructor(private navCtrl: NavController, private logger: Logger, private user: Users) { 

    } 

    generateOTP(newstate) { 
    this.logger.info("invoking generateOTP FN"); 
    var _this = this; 
    this.user.generateOTP(this.loginId, function(result,data){ 
     if(result == '1') { 
     alert(data); 
     _this.showRePasswd = !_this.showRePasswd; 
     _this.isDisabled = true; 
     _this.isOn = newstate; 
     } 
     else { 
     //this.showRePasswd = this.showRePasswd; 
     alert(data); 
     } 
    }) 
    } 

    resetPassword() { 
    this.logger.info("invoking resetPassword FN"); 
    var _this = this; 

    this.user.resetPassword(this.passwd, function(result,data) { 
     if(result == '1') { 
     alert(data); 
     _this.navCtrl.push(LoginPage); 
     } 
     else { 
     alert(data); 
     } 
    }) 
    } 
} 

मैं [ngClass] की कोशिश की, लेकिन मैं सफलता कॉलबैक के बाद अक्षम करें मेरी div टैग बनाने के लिए सक्षम नहीं हूँ देखो ।

मैं भी करने के लिए अपने इनपुट क्षेत्र और बटन बनाने के लिए [disabled] का उपयोग कर, लेकिन यहां काम नहीं कर रहा

है अक्षम एक div टैग के लिए, लेकिन मेरे मामले में एक demo काम नहीं कर रहा

मेरे आवश्यकता है की कोशिश की सफलता कॉलबैक के बाद अक्षम हो जाएं

उत्तर

10

आप की तरह

<div [attr.disabled]="isDisabled ? true : null"> 

विशेषता जोड़ सकते हैं लेकिन disabled विशेषता <div> का समर्थन नहीं करता है।

शायद यह है कि तुम क्या करता है कि .isDiabled विकलांग देखने के कुछ कस्टम सीएसएस के साथ चाहते हैं

<div>(click)="isDisabled ? $event.stopPropagation() : myClickHandler($event); isDisabled ? false : null" 
    [class.isDisabled]="isDisabled"></div> 

है।

इनलाइन के बजाय कोड डालने का तरीका बनाना बेहतर हो सकता है।

+2

ngClass का उपयोग करने के लिए मैंने आपके उत्तर की कोशिश की लेकिन फिर भी मैं अपने div टैग –

+1

'div' में अपना इनपुट फ़ील्ड संपादित करने में सक्षम था, 'div' अक्षम नहीं किया जा सकता है (HTML सीमा, कोणीय 2 सीमा नहीं)। आप 'अक्षम' विशेषता सेट कर सकते हैं और उस पर सीएसएस लागू कर सकते हैं या आप सभी बाल तत्वों पर 'अक्षम' सेट कर सकते हैं जिन्हें वास्तव में व्यक्तिगत रूप से अक्षम किया जा सकता है। –

+0

@MohanGopi ने जो जोड़ा है उसे जोड़ने के लिए, (क्लिक करें) div की घटना [attr.disabled] सेट भी उत्पन्न होती है। इसलिए हम उस div के क्लिक को अक्षम नहीं कर सकते हैं। – shanti

0

div तत्व को फॉर्म नियंत्रणों जैसे अक्षम नहीं किया जा सकता है। आप इसके बजाय div में फॉर्म नियंत्रण अक्षम कर सकते हैं।

परंतु उदाहरण कस्टम वर्ग "अक्षम"

styles: [` 
    .button { 
     width: 120px; 
     border: medium solid black; 
    } 

    .active { 
     background-color: red; 
    } 

    .disabled { 
     color: gray; 
     border: medium solid gray; 
    } 
    `] 
+0

क्योंकि मैंने पहले ही उल्लेख किया है कि शैली का उपयोग नहीं किया जाता है –

+0

मैं वास्तव में समझ नहीं पा रहा हूं कि आप क्या हासिल करना चाहते हैं। क्या आप वांछित प्रभाव प्रदान कर सकते हैं? [ngClass] = "{सक्रिय: isOn, अक्षम: isDisabled}"> आपकी टेम्पलेट फ़ाइल में है। – jmachnik

+0

@ मोहनगोपी आप एक कस्टम कंटेनर (निर्देश) भी बना सकते हैं जो सभी बच्चों को मांग पर अक्षम कर देगा। – jmachnik