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);









share|improve this question























  • 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















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);









share|improve this question























  • 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













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);









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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













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>





share|improve this answer




















  • 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










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',
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%2f53236301%2fselect-list-in-angularjs%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








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>





share|improve this answer




















  • 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














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>





share|improve this answer




















  • 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












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>





share|improve this answer












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>






share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















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.





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.




draft saved


draft discarded














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





















































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

Darth Vader #20

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Ondo