angular - Angular2: Form control not found -


i've created form inside ngoninit() method:

this.cardform = this.fb.group({     card_number: ['', validators.required],     holdername: ['', validators.required],     expiry: ['', validators.required],     cvc: ['', validators.required],     address_line1: ['', validators.required],     address_line2: ['', validators.required],     address_city: ['', validators.required],     address_state: ['', validators.required],     address_zip: ['', validators.required],     address_country: ['', validators.required]   }); 

on template:

<form [formgroup]="cardform" novalidate="novalidate">   <div class="form-group">     <label for="cardnumber">card number</label>     <input        type="text"       name="cardnumber"       class="input-transparent form-control"       formcontrolname="card_number"       data-mask="9999-9999-9999-9999"       placeholder="____-____-____-____"       required="required">  </div> 

nevertheless, i'm getting error:

error error: cannot find control name: 'card_number'

you don't have id in input tag. try insert

<input     id="card_number"    ... > 

update 1 if provide more code lot. since there validators.required should have value. anyways, hunch try use on input.

[formcontrol]="cardform.controls['card_number']"

instead of

formcontrolname="card_number"


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -