Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to execute 'setAttribute' on 'Element': ']' is not a valid attribute name. angular 4

Tags:

angular

I am getting the following error:

Failed to execute 'setAttribute' on 'Element': ']' is not a valid attribute name.

I simply made model:

export interface ModalComponentModel {
    username: string;
    password: string;
    password2: string;
    description: string;
}

I used it in my component:

component:

model: ModalComponentModel;

Then I tried to use it in my html file:

    <div class="modal-header">
    <h4 class="modal-title text-center">Edit Profile</h4>
    <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
        <span aria-hidden="true">&times;</span>
    </button>
</div>
<div class="modal-body">
    <div class="row">
        <div class="col-md-2 col-md-offset-2">
            <form class="form" role="form" (ngSubmit)="whatDoesThisFormDo()">
                <div class="form-group">
                    <label for="username">Username</label>
                    <input type="text" class="form-control" name="username" id="username" placeholder="Your username"
                           [(ngModel)]="model.username">
                </div>
                <div class="form-group">
                    <label for="password1">Password</label>
                    <input type="password" class="form-control" name="password1" id="password1" placeholder="Your password"
                           [(ngModel)]="model.password">
                </div>
                <div class="form-group">
                    <label for="password2">Confirm Password</label>
                    <input type="password" class="form-control" name="password2" id="password2" placeholder="Your password"
                           [(ngModel)]="model.password2">
                </div>
                <div class="form-group">
                    <textarea rows="4" cols="50" placeholder="Description" [(ngModel)]="model.description"]></textarea>
                </div>
                <div class="row">
                    <div class="col-xs-1">
                        <button value="update" type="button" class="btn btn-primary pull-left">Update</button>
                    </div>
                    <div class="col-xs-1">
                        <button value="cancel" type="button" class="btn btn-primary pull-left">Cancel</button>
                        <div class="clear"></div>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-outline-dark" (click)="activeModal.close('Close click')">Close</button>
</div>

It was working fine until I added to model, full HTML is above as requested.

I am also not able to get the buttons correctly side by side.

like image 699
Mike3355 Avatar asked Aug 21 '17 17:08

Mike3355


3 Answers

[(ngModel)]="model.description"] // ']' is added unnecessarily

change it to

[(ngModel)]="model.description"

Don't wrap it to a square bracket.

Update:

You can initialize your model variable as follow according to your need,

model:ModalComponentModel=<ModalComponentModel>{};

OR

model:ModalComponentModel=<ModalComponentModel>[];
like image 108
Nikhil Shah Avatar answered Nov 08 '22 20:11

Nikhil Shah


Problem is in this line

Change

From

  <textarea rows="4" cols="50" placeholder="Description" [(ngModel)]="model.description"]></textarea>

to

  <textarea rows="4" cols="50" placeholder="Description" [(ngModel)]="model.description"></textarea>
like image 15
Sajeetharan Avatar answered Nov 08 '22 19:11

Sajeetharan


You have problem in this line of code:

<textarea rows="4" cols="50" placeholder="Description" [(ngModel)]="model.description"]></textarea>

It should be:

<textarea rows="4" cols="50" placeholder="Description" [(ngModel)]="model.description"></textarea>

There is an extra bracket that is causing this error.

like image 8
vertika Avatar answered Nov 08 '22 21:11

vertika