Angular form group: cannot find control with unspecified name attribute












1















I'm having a problem with my Angular app.
I'm trying to create 3 forms.
Here is my template:



<div *ngFor="let item of formNames; index as i" >
{{formNames[i]}}
<form [formGroup]='formFields[i]'>
<label>
Name:
<input type="text" [formControl]="formFields[i].name">
</label>
<label>
All:
<input type="text" [formControl]="formFields[i].all">
</label>
<label>
Done:
<input type="text" [formControl]="formFields[i].done">
</label>
<label>
Ctrl:
<input type="text" [formControl]="formFields[i].ctrl">
</label>
<label>
Rjct:
<input type="text" [formControl]="formFields[i].rjct">
</label>
</form>
</div>


The problem is that when the page loads, it renders only the first {{formnames[i]}}. Console says "ERROR Error: Cannot find control with unspecified name attribute".



Here is the code I use to render FormGroups:



export class TableDataFormComponent {
formFields: Array<any> = fields;
formNames = FORMINPUTS;
say = f;
}

let f = function() {console.log(this.formFields); };

const FORMINPUTS: Array<string> = ;

TableHeaders.HEADERS.forEach((item) => {
FORMINPUTS.push(item);
});

let fields: Array<FormGroup> = ;

for (let i = 0; i < FORMINPUTS.length; i++) {
fields[i] = new FormGroup({
name: new FormControl(''),
all: new FormControl(''),
done: new FormControl(''),
ctrl: new FormControl(''),
rjct: new FormControl('')
});
}


Here is the video of the problem: https://yadi.sk/i/4GnZpJLV38oWMg



Stackblitz for some reason is not working for my project, but the source code is here: https://stackblitz.com/github/kulaska/Table-app/tree/adding_forms_branch



I don't understand why data renders after interacting with buttons or input elements. It somehow triggers creating of new FormGroup.
Obviously, I need all of them to be created at the same time, without interacting with DOM.
Has anyone had the same issue? What do I do to solve this?
I'd really appreciate your help










share|improve this question























  • Remove [formGroup]='formFields[i]' from form tag.

    – Sunil Singh
    Nov 15 '18 at 21:13
















1















I'm having a problem with my Angular app.
I'm trying to create 3 forms.
Here is my template:



<div *ngFor="let item of formNames; index as i" >
{{formNames[i]}}
<form [formGroup]='formFields[i]'>
<label>
Name:
<input type="text" [formControl]="formFields[i].name">
</label>
<label>
All:
<input type="text" [formControl]="formFields[i].all">
</label>
<label>
Done:
<input type="text" [formControl]="formFields[i].done">
</label>
<label>
Ctrl:
<input type="text" [formControl]="formFields[i].ctrl">
</label>
<label>
Rjct:
<input type="text" [formControl]="formFields[i].rjct">
</label>
</form>
</div>


The problem is that when the page loads, it renders only the first {{formnames[i]}}. Console says "ERROR Error: Cannot find control with unspecified name attribute".



Here is the code I use to render FormGroups:



export class TableDataFormComponent {
formFields: Array<any> = fields;
formNames = FORMINPUTS;
say = f;
}

let f = function() {console.log(this.formFields); };

const FORMINPUTS: Array<string> = ;

TableHeaders.HEADERS.forEach((item) => {
FORMINPUTS.push(item);
});

let fields: Array<FormGroup> = ;

for (let i = 0; i < FORMINPUTS.length; i++) {
fields[i] = new FormGroup({
name: new FormControl(''),
all: new FormControl(''),
done: new FormControl(''),
ctrl: new FormControl(''),
rjct: new FormControl('')
});
}


Here is the video of the problem: https://yadi.sk/i/4GnZpJLV38oWMg



Stackblitz for some reason is not working for my project, but the source code is here: https://stackblitz.com/github/kulaska/Table-app/tree/adding_forms_branch



I don't understand why data renders after interacting with buttons or input elements. It somehow triggers creating of new FormGroup.
Obviously, I need all of them to be created at the same time, without interacting with DOM.
Has anyone had the same issue? What do I do to solve this?
I'd really appreciate your help










share|improve this question























  • Remove [formGroup]='formFields[i]' from form tag.

    – Sunil Singh
    Nov 15 '18 at 21:13














1












1








1








I'm having a problem with my Angular app.
I'm trying to create 3 forms.
Here is my template:



<div *ngFor="let item of formNames; index as i" >
{{formNames[i]}}
<form [formGroup]='formFields[i]'>
<label>
Name:
<input type="text" [formControl]="formFields[i].name">
</label>
<label>
All:
<input type="text" [formControl]="formFields[i].all">
</label>
<label>
Done:
<input type="text" [formControl]="formFields[i].done">
</label>
<label>
Ctrl:
<input type="text" [formControl]="formFields[i].ctrl">
</label>
<label>
Rjct:
<input type="text" [formControl]="formFields[i].rjct">
</label>
</form>
</div>


The problem is that when the page loads, it renders only the first {{formnames[i]}}. Console says "ERROR Error: Cannot find control with unspecified name attribute".



Here is the code I use to render FormGroups:



export class TableDataFormComponent {
formFields: Array<any> = fields;
formNames = FORMINPUTS;
say = f;
}

let f = function() {console.log(this.formFields); };

const FORMINPUTS: Array<string> = ;

TableHeaders.HEADERS.forEach((item) => {
FORMINPUTS.push(item);
});

let fields: Array<FormGroup> = ;

for (let i = 0; i < FORMINPUTS.length; i++) {
fields[i] = new FormGroup({
name: new FormControl(''),
all: new FormControl(''),
done: new FormControl(''),
ctrl: new FormControl(''),
rjct: new FormControl('')
});
}


Here is the video of the problem: https://yadi.sk/i/4GnZpJLV38oWMg



Stackblitz for some reason is not working for my project, but the source code is here: https://stackblitz.com/github/kulaska/Table-app/tree/adding_forms_branch



I don't understand why data renders after interacting with buttons or input elements. It somehow triggers creating of new FormGroup.
Obviously, I need all of them to be created at the same time, without interacting with DOM.
Has anyone had the same issue? What do I do to solve this?
I'd really appreciate your help










share|improve this question














I'm having a problem with my Angular app.
I'm trying to create 3 forms.
Here is my template:



<div *ngFor="let item of formNames; index as i" >
{{formNames[i]}}
<form [formGroup]='formFields[i]'>
<label>
Name:
<input type="text" [formControl]="formFields[i].name">
</label>
<label>
All:
<input type="text" [formControl]="formFields[i].all">
</label>
<label>
Done:
<input type="text" [formControl]="formFields[i].done">
</label>
<label>
Ctrl:
<input type="text" [formControl]="formFields[i].ctrl">
</label>
<label>
Rjct:
<input type="text" [formControl]="formFields[i].rjct">
</label>
</form>
</div>


The problem is that when the page loads, it renders only the first {{formnames[i]}}. Console says "ERROR Error: Cannot find control with unspecified name attribute".



Here is the code I use to render FormGroups:



export class TableDataFormComponent {
formFields: Array<any> = fields;
formNames = FORMINPUTS;
say = f;
}

let f = function() {console.log(this.formFields); };

const FORMINPUTS: Array<string> = ;

TableHeaders.HEADERS.forEach((item) => {
FORMINPUTS.push(item);
});

let fields: Array<FormGroup> = ;

for (let i = 0; i < FORMINPUTS.length; i++) {
fields[i] = new FormGroup({
name: new FormControl(''),
all: new FormControl(''),
done: new FormControl(''),
ctrl: new FormControl(''),
rjct: new FormControl('')
});
}


Here is the video of the problem: https://yadi.sk/i/4GnZpJLV38oWMg



Stackblitz for some reason is not working for my project, but the source code is here: https://stackblitz.com/github/kulaska/Table-app/tree/adding_forms_branch



I don't understand why data renders after interacting with buttons or input elements. It somehow triggers creating of new FormGroup.
Obviously, I need all of them to be created at the same time, without interacting with DOM.
Has anyone had the same issue? What do I do to solve this?
I'd really appreciate your help







javascript html angular






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 20:42









kulaskakulaska

225




225













  • Remove [formGroup]='formFields[i]' from form tag.

    – Sunil Singh
    Nov 15 '18 at 21:13



















  • Remove [formGroup]='formFields[i]' from form tag.

    – Sunil Singh
    Nov 15 '18 at 21:13

















Remove [formGroup]='formFields[i]' from form tag.

– Sunil Singh
Nov 15 '18 at 21:13





Remove [formGroup]='formFields[i]' from form tag.

– Sunil Singh
Nov 15 '18 at 21:13












1 Answer
1






active

oldest

votes


















3














Your best bet is to use the FormBuilder.



this.formBuilder.array([ this.createItem() ])



createItem(): FormGroup {
return this.formBuilder.group({
name: '',
all: '',
done: '',
...
});
}


And your template will need to use
formArrayName="fields" and [formGroupName]="i"



See this article for more details:
https://alligator.io/angular/reactive-forms-formarray-dynamic-fields/






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327606%2fangular-form-group-cannot-find-control-with-unspecified-name-attribute%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Your best bet is to use the FormBuilder.



    this.formBuilder.array([ this.createItem() ])



    createItem(): FormGroup {
    return this.formBuilder.group({
    name: '',
    all: '',
    done: '',
    ...
    });
    }


    And your template will need to use
    formArrayName="fields" and [formGroupName]="i"



    See this article for more details:
    https://alligator.io/angular/reactive-forms-formarray-dynamic-fields/






    share|improve this answer






























      3














      Your best bet is to use the FormBuilder.



      this.formBuilder.array([ this.createItem() ])



      createItem(): FormGroup {
      return this.formBuilder.group({
      name: '',
      all: '',
      done: '',
      ...
      });
      }


      And your template will need to use
      formArrayName="fields" and [formGroupName]="i"



      See this article for more details:
      https://alligator.io/angular/reactive-forms-formarray-dynamic-fields/






      share|improve this answer




























        3












        3








        3







        Your best bet is to use the FormBuilder.



        this.formBuilder.array([ this.createItem() ])



        createItem(): FormGroup {
        return this.formBuilder.group({
        name: '',
        all: '',
        done: '',
        ...
        });
        }


        And your template will need to use
        formArrayName="fields" and [formGroupName]="i"



        See this article for more details:
        https://alligator.io/angular/reactive-forms-formarray-dynamic-fields/






        share|improve this answer















        Your best bet is to use the FormBuilder.



        this.formBuilder.array([ this.createItem() ])



        createItem(): FormGroup {
        return this.formBuilder.group({
        name: '',
        all: '',
        done: '',
        ...
        });
        }


        And your template will need to use
        formArrayName="fields" and [formGroupName]="i"



        See this article for more details:
        https://alligator.io/angular/reactive-forms-formarray-dynamic-fields/







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 '18 at 20:59

























        answered Nov 15 '18 at 20:48









        Nadhir FaltaNadhir Falta

        1,035315




        1,035315
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327606%2fangular-form-group-cannot-find-control-with-unspecified-name-attribute%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python