Hey there,
I remember reading a similar problem in here about issues with Beta 10 on Angular RC3 .
Trust me when I say I’ve tried a lot of ‘solutions’ and I’ve spent days on this issue, nothing works except using old plain Angular instead of Ionic flavour.
The reason for this ^ is because I’ve given up on a solution in Ionic. I’m going to wait for another release or better yet, a stable release of Ionic before.
I’m posting this for people with a similar issue and hopefully save someone else the headaches and lost time.
The problem arises when using the new Form module in RC3.
Given this code:
<form [formGroup]="itemForm" (ngSubmit)="onSubmit()">
<ion-input type="text" formControlName="name" [(ngModel)]="model.name" placeholder="Name"></ion-input>
</form>
import {Component, ViewChild} from '@angular/core';
import {REACTIVE_FORM_DIRECTIVES, FormControl, FormGroup, FormArray, Validators} from '@angular/forms';
...
export class ItemFormPage {
@ViewChild('itemFormSlider') itemFormSlider: Slides;
itemForm: FormGroup;
model: any;
constructor( ) {
this.model = {
name: "test2",
description: "trest",
item_category_id: "5",
location_id: "6",
item_attributes: [{
"3": { value: "£300" },
"4": { material: "Cotton" },
"5": { color: "green" }
}]
};
this.itemForm = new FormGroup({
name: new FormControl(''),
description: new FormControl(''),
item_category_id: new FormControl(''),
location_id: new FormControl(''),
item_attributes: new FormArray([ ])
});
Gives the following error:
4 538151 group EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in build/pages/item-form/item-form.html:17:27
ORIGINAL EXCEPTION: No value accessor for 'name'
ORIGINAL STACKTRACE:
Error: No value accessor for 'name'
at new BaseException (http://192.168.0.46:8100/build/js/app.bundle.js:2576:23)
at _throwError (http://192.168.0.46:8100/build/js/app.bundle.js:37625:11)
at Object.setUpControl (http://192.168.0.46:8100/build/js/app.bundle.js:37600:9)
at FormGroupDirective.addControl (http://192.168.0.46:8100/build/js/app.bundle.js:37168:18)
at NgModel._addControl (http://192.168.0.46:8100/build/js/app.bundle.js:36692:65)
at NgModel.ngOnChanges (http://192.168.0.46:8100/build/js/app.bundle.js:36651:18)
at DebugAppView._View_ItemFormPage0.detectChangesInternal (ItemFormPage.template.js:480:48)
at DebugAppView.AppView.detectChanges (http://192.168.0.46:8100/build/js/app.bundle.js:30729:14)
at DebugAppView.detectChanges (http://192.168.0.46:8100/build/js/app.bundle.js:30834:44)
at DebugAppView.AppView.detectViewChildrenChanges (http://192.168.0.46:8100/build/js/app.bundle.js:30755:19)
ERROR CONTEXT:
[object Object]
Changing the Ionic input to:
<input type="text" formControlName="name" [(ngModel)]="model.name" placeholder="Name">
does the trick, I’m obviously not happy as I want to use Ionic’ helpers.
Any suggestions are welcomed.