2016-12-09 11 views
5

Jestem nowy Kątowymi 2.Jak napisać 2 formularze sprawdzania poprawności w pojedynczym pliku ts przy użyciu Angular 2?

Mamy 2 formularzy w HTML z odrębnymi znaczników DIV, gdy 1-ta div zrealizowanych, 2. div jest fałszywy stan. Za każdym razem, gdy sukces oddzwoni, drugi div będzie stanem rzeczywistym. Ilekroć przychodzi 2.div stan prawdziwy, wyświetli się this error message.

Poniżej jest mój kod plik .ts:

constructor(public navCtrl: NavController, 
      public navParams: NavParams, 
      public formBuilder:FormBuilder, 
      public logger: Logger, 
      public rest: Rest 
      ) { 
    this.customer_id=this.navParams.get('customer_id'); 
    this.mobile=this.navParams.get('mobile'); 

    this.myForm = formBuilder.group({ 
    'otpNumber': ['', Validators.required] 
    //'password': ['', Validators.required] 
    }); 

    this.myForm1 = formBuilder.group({ 
    'newpassword': ['', Validators.required], 
    'conformPassword': ['', Validators.required] 
    }); 

    this.getotp(); 
} 

submit(){ 
    let validateOTPObj = { 
    loginId: this.mobile, 
    otp:this.myForm.value.otpNumber 
    } 

    this.logger.debug("checking the otpNumber"+JSON.stringify(validateOTPObj)); 

    this.rest.post('/validateOTP' ,validateOTPObj) 
    .subscribe((result)=>{ 
     this.logger.debug("checking data of success " + JSON.stringify(result)); 

     if(result.status=='1'){ 
     //this.navCtrl.push(,{}); 
     //this.access_token = id; 
     this.firstDiv=false; 
     this.secondDiv = true; 
     this.logger.debug("checking access tocken "+ this.access_token); 
     alert("otp success"); 
     } else { 
     this.logger.info("error"); 
     } 
    }); 
} 
+1

można udostępnić strony HTML? –

+2

byłoby lepiej, gdybyś udostępnił swój html, ale na podstawie komunikatu o błędzie być może właśnie zapomniałeś zadeklarować myForm/myForm1 jako formGroup w html '[formGroup] =" myForm "[formGroup] =" myForm1 "' –

Odpowiedz

0

Wystarczy zadzwonić różny sposób dla różnych formach:

HTML:

<form (submit)= 'form1()'> 
<input type='text' required > 
<input type='submit' value='submit' /> 

<form (submit)= 'form2()'> 
<input type='text' required > 
<input type='submit' value='submit' /> 

TS:

form1(){ 
console.log('form 1') 
    } 

form2(){ 
console.log('form 2') 
    } 
Powiązane problemy