Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  192] [ 5]  / answers: 1 / hits: 6246  / 7 Years ago, mon, january 22, 2018, 12:00:00

putting together a simple form, and upon submission I am getting the following error:



ERROR TypeError: _this.form.get is not a function
at VM46 vendor.js:29003
at Array.forEach (<anonymous>)
at FormGroupDirective._updateDomValue (VM46 vendor.js:29002)
at FormGroupDirective.ngOnChanges (VM46 vendor.js:28820)
at checkAndUpdateDirectiveInline (VM46 vendor.js:12445)
at checkAndUpdateNodeInline (VM46 vendor.js:13951)
at checkAndUpdateNode (VM46 vendor.js:13894)
at debugCheckAndUpdateNode (VM46 vendor.js:14766)
at debugCheckDirectivesFn (VM46 vendor.js:14707)
at Object.View_FeedformPage_0._co [as updateDirectives] (VM145


The function that I am running is very simple... I am just trying to log the value of the form to the console at the moment (which it does) but I am still throwing an error, which I need to address. My imports/function is as follows :



import { Validators, FormBuilder, FormGroup, FormControl } from '@angular/forms';

constructor(public navCtrl: NavController, public navParams: NavParams,
public viewCtrl: ViewController, private formBuilder: FormBuilder,
public storage: Storage) {

this.feedForm = this.formBuilder.group({

description: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(250)]]


});
}

addFeed(){

this.feedForm = this.feedForm.value;
console.log(this.feedForm);

}


The HTML is as follows:



<form [formGroup]=feedForm (ngSubmit)=addFeed()>
<ion-item>
<ion-label stacked>Update: </ion-label>
<ion-textarea formControlName=description placeholder=Leave Comment Here...></ion-textarea>
</ion-item>
<button ion-button type=submit [disabled]=!feedForm.valid>Update</button>
</form>


The fact that I cannot find anything to reference except this tells me that I am overlooking something obvious. Any insight would be appreciated.


More From » angular

 Answers
2

If you need the value of your form either logged or posted try this:



1- Delete this.feedForm = this.feedForm.value;

2- Change your console.log to this console.log(this.feedForm.getRawValue());



getRawValue will give you all fields values even if they are disabled


[#15669] Sunday, January 21, 2018, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
corie

Total Points: 371
Total Questions: 110
Total Answers: 113

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
;