Select List in AngularJs
up vote
1
down vote
favorite
I have an template Driven form in my Angular application, I tried a lot but I am not able to figure out what wrong with my code.
I want to return the selected value from select list and save it to the Firebase database.I have 5 input fields all fields are returning the data and i am able to save to the Firebase except select list value whose data returns as undefined.
This is my template-driven form code:
<div class="formalign">
<form #f="ngForm" (ngSubmit)="save(f.value)">
<div class="form-group">
<label for="title">Title</label>
<input ngModel name="title" id="title" type="text" class="form-control">
</div>
<!--for Price-->
<div class="form-group">
<label for="price">Price</label>
<div class="input-group-prepend">
<span class="input-group-text">INR</span>
<input ngModel name="price" id="price" type="number" class="form-control">
</div>
</div>
<!--category-->
<div class="form-group">
<label for="catagory">Catagory</label>
<select ngModel name="catagory" id="catagory" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
<!--Image-->
<div class="form-group">
<label for="image">Image</label>
<input ngModel name="imageurl" id="image" type="text" class="form-control">
</div>
<!--Save Button-->
<button class="btn btn-primary">Save</button>
</form>
</div>
After clicking on Save button catagory select list returns undefined value.
How i can resolve that?
Below is my Two-way data bidning update with component code:-
<div class="form-group">
<label for="catagory">Catagory</label>
<select [(ngModel)]="catagoryData" name="catagoryData" id="catagoryData" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
In my component.ts i am trying to print the value but it is still giving me undefined value:-
catagoryData:string;
console.log("The Catagory",this.catagoryData);
angular
add a comment |
up vote
1
down vote
favorite
I have an template Driven form in my Angular application, I tried a lot but I am not able to figure out what wrong with my code.
I want to return the selected value from select list and save it to the Firebase database.I have 5 input fields all fields are returning the data and i am able to save to the Firebase except select list value whose data returns as undefined.
This is my template-driven form code:
<div class="formalign">
<form #f="ngForm" (ngSubmit)="save(f.value)">
<div class="form-group">
<label for="title">Title</label>
<input ngModel name="title" id="title" type="text" class="form-control">
</div>
<!--for Price-->
<div class="form-group">
<label for="price">Price</label>
<div class="input-group-prepend">
<span class="input-group-text">INR</span>
<input ngModel name="price" id="price" type="number" class="form-control">
</div>
</div>
<!--category-->
<div class="form-group">
<label for="catagory">Catagory</label>
<select ngModel name="catagory" id="catagory" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
<!--Image-->
<div class="form-group">
<label for="image">Image</label>
<input ngModel name="imageurl" id="image" type="text" class="form-control">
</div>
<!--Save Button-->
<button class="btn btn-primary">Save</button>
</form>
</div>
After clicking on Save button catagory select list returns undefined value.
How i can resolve that?
Below is my Two-way data bidning update with component code:-
<div class="form-group">
<label for="catagory">Catagory</label>
<select [(ngModel)]="catagoryData" name="catagoryData" id="catagoryData" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
In my component.ts i am trying to print the value but it is still giving me undefined value:-
catagoryData:string;
console.log("The Catagory",this.catagoryData);
angular
Change the option code [value] to [ngValue]. Are you initializing the categoryData value in the ngOnInit()? Does the value of categoryData have a matching value to what you are setting in the option?
– Russell D
Nov 11 at 2:02
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have an template Driven form in my Angular application, I tried a lot but I am not able to figure out what wrong with my code.
I want to return the selected value from select list and save it to the Firebase database.I have 5 input fields all fields are returning the data and i am able to save to the Firebase except select list value whose data returns as undefined.
This is my template-driven form code:
<div class="formalign">
<form #f="ngForm" (ngSubmit)="save(f.value)">
<div class="form-group">
<label for="title">Title</label>
<input ngModel name="title" id="title" type="text" class="form-control">
</div>
<!--for Price-->
<div class="form-group">
<label for="price">Price</label>
<div class="input-group-prepend">
<span class="input-group-text">INR</span>
<input ngModel name="price" id="price" type="number" class="form-control">
</div>
</div>
<!--category-->
<div class="form-group">
<label for="catagory">Catagory</label>
<select ngModel name="catagory" id="catagory" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
<!--Image-->
<div class="form-group">
<label for="image">Image</label>
<input ngModel name="imageurl" id="image" type="text" class="form-control">
</div>
<!--Save Button-->
<button class="btn btn-primary">Save</button>
</form>
</div>
After clicking on Save button catagory select list returns undefined value.
How i can resolve that?
Below is my Two-way data bidning update with component code:-
<div class="form-group">
<label for="catagory">Catagory</label>
<select [(ngModel)]="catagoryData" name="catagoryData" id="catagoryData" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
In my component.ts i am trying to print the value but it is still giving me undefined value:-
catagoryData:string;
console.log("The Catagory",this.catagoryData);
angular
I have an template Driven form in my Angular application, I tried a lot but I am not able to figure out what wrong with my code.
I want to return the selected value from select list and save it to the Firebase database.I have 5 input fields all fields are returning the data and i am able to save to the Firebase except select list value whose data returns as undefined.
This is my template-driven form code:
<div class="formalign">
<form #f="ngForm" (ngSubmit)="save(f.value)">
<div class="form-group">
<label for="title">Title</label>
<input ngModel name="title" id="title" type="text" class="form-control">
</div>
<!--for Price-->
<div class="form-group">
<label for="price">Price</label>
<div class="input-group-prepend">
<span class="input-group-text">INR</span>
<input ngModel name="price" id="price" type="number" class="form-control">
</div>
</div>
<!--category-->
<div class="form-group">
<label for="catagory">Catagory</label>
<select ngModel name="catagory" id="catagory" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
<!--Image-->
<div class="form-group">
<label for="image">Image</label>
<input ngModel name="imageurl" id="image" type="text" class="form-control">
</div>
<!--Save Button-->
<button class="btn btn-primary">Save</button>
</form>
</div>
After clicking on Save button catagory select list returns undefined value.
How i can resolve that?
Below is my Two-way data bidning update with component code:-
<div class="form-group">
<label for="catagory">Catagory</label>
<select [(ngModel)]="catagoryData" name="catagoryData" id="catagoryData" class="form-control">
<option value=""></option>
<option *ngFor="let c of valuearray" [value]="c.$key">
c.name
</option>
</select>
</div>
In my component.ts i am trying to print the value but it is still giving me undefined value:-
catagoryData:string;
console.log("The Catagory",this.catagoryData);
angular
angular
edited Nov 10 at 17:51
asked Nov 10 at 5:40
Sam
65
65
Change the option code [value] to [ngValue]. Are you initializing the categoryData value in the ngOnInit()? Does the value of categoryData have a matching value to what you are setting in the option?
– Russell D
Nov 11 at 2:02
add a comment |
Change the option code [value] to [ngValue]. Are you initializing the categoryData value in the ngOnInit()? Does the value of categoryData have a matching value to what you are setting in the option?
– Russell D
Nov 11 at 2:02
Change the option code [value] to [ngValue]. Are you initializing the categoryData value in the ngOnInit()? Does the value of categoryData have a matching value to what you are setting in the option?
– Russell D
Nov 11 at 2:02
Change the option code [value] to [ngValue]. Are you initializing the categoryData value in the ngOnInit()? Does the value of categoryData have a matching value to what you are setting in the option?
– Russell D
Nov 11 at 2:02
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Here is the two-way data binding example from Angular Template Driven Forms. You need to two-way bind your select's ngModel to a property on your controller, in this case model.power.
<div class="form-group">
<label for="power">Hero Power</label>
<select class="form-control" id="power"
required
[(ngModel)]="model.power" name="power">
<option *ngFor="let pow of powers" [value]="pow">pow</option>
</select>
</div>
i have tried your solution ,i have attach updated code in my question but it is still giving me an undefined
– Sam
Nov 10 at 17:52
Change the option code [value] to [ngValue].
– Russell D
Nov 12 at 2:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Here is the two-way data binding example from Angular Template Driven Forms. You need to two-way bind your select's ngModel to a property on your controller, in this case model.power.
<div class="form-group">
<label for="power">Hero Power</label>
<select class="form-control" id="power"
required
[(ngModel)]="model.power" name="power">
<option *ngFor="let pow of powers" [value]="pow">pow</option>
</select>
</div>
i have tried your solution ,i have attach updated code in my question but it is still giving me an undefined
– Sam
Nov 10 at 17:52
Change the option code [value] to [ngValue].
– Russell D
Nov 12 at 2:10
add a comment |
up vote
0
down vote
Here is the two-way data binding example from Angular Template Driven Forms. You need to two-way bind your select's ngModel to a property on your controller, in this case model.power.
<div class="form-group">
<label for="power">Hero Power</label>
<select class="form-control" id="power"
required
[(ngModel)]="model.power" name="power">
<option *ngFor="let pow of powers" [value]="pow">pow</option>
</select>
</div>
i have tried your solution ,i have attach updated code in my question but it is still giving me an undefined
– Sam
Nov 10 at 17:52
Change the option code [value] to [ngValue].
– Russell D
Nov 12 at 2:10
add a comment |
up vote
0
down vote
up vote
0
down vote
Here is the two-way data binding example from Angular Template Driven Forms. You need to two-way bind your select's ngModel to a property on your controller, in this case model.power.
<div class="form-group">
<label for="power">Hero Power</label>
<select class="form-control" id="power"
required
[(ngModel)]="model.power" name="power">
<option *ngFor="let pow of powers" [value]="pow">pow</option>
</select>
</div>
Here is the two-way data binding example from Angular Template Driven Forms. You need to two-way bind your select's ngModel to a property on your controller, in this case model.power.
<div class="form-group">
<label for="power">Hero Power</label>
<select class="form-control" id="power"
required
[(ngModel)]="model.power" name="power">
<option *ngFor="let pow of powers" [value]="pow">pow</option>
</select>
</div>
answered Nov 10 at 6:37
Russell D
1197
1197
i have tried your solution ,i have attach updated code in my question but it is still giving me an undefined
– Sam
Nov 10 at 17:52
Change the option code [value] to [ngValue].
– Russell D
Nov 12 at 2:10
add a comment |
i have tried your solution ,i have attach updated code in my question but it is still giving me an undefined
– Sam
Nov 10 at 17:52
Change the option code [value] to [ngValue].
– Russell D
Nov 12 at 2:10
i have tried your solution ,i have attach updated code in my question but it is still giving me an undefined
– Sam
Nov 10 at 17:52
i have tried your solution ,i have attach updated code in my question but it is still giving me an undefined
– Sam
Nov 10 at 17:52
Change the option code [value] to [ngValue].
– Russell D
Nov 12 at 2:10
Change the option code [value] to [ngValue].
– Russell D
Nov 12 at 2:10
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236301%2fselect-list-in-angularjs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Change the option code [value] to [ngValue]. Are you initializing the categoryData value in the ngOnInit()? Does the value of categoryData have a matching value to what you are setting in the option?
– Russell D
Nov 11 at 2:02