angular get selected value in multiple selects inside ng-repeat
<tr ng-repeat="x in my_array">
<td>
<select name='[{{$index}}].Name' >
<option ng-repeat="sr in anotherArray" value="{{sr}}">
{{sr}}
</option>
</select>
</td>
</tr>
i have a table with rows populated by ng-repeat: my_array
there is another array : anotherArray
l want when the rows are repeated in angular for my_array to have its own value for [{{$index}}].Name to be based on the selected value for that particular row.
when l post the data to api [{{$index}}].Name will only have the same value even if l select different item for each rows.
l tried using ng-options as it was said its good for
of is there an easy way to get around it .
am populating the anotherArray and anotherArray
on different on same page but they are just an array with string values in it like as below
$scope.anotherArray= ;
$scope.add = function () {
$scope.errortext = "";
if (!$scope.addMe) { return; }
if ($scope.variants.indexOf($scope.addMe) == -1) {
$scope.anotherArray.push($scope.addMe);
}
}
the desired result is like
in image i_prepopulateOnRow1 ,i_prepopulateOnRow2 ...i_prepopulateOnRow upto Nth are add from anotherArray
when ever a new row from my_array is added it must have a select option for anotherArray thus in each row l can have value for i_prepopulateOnRow
the reason am using name as [{{$index}}].Name its becasue am posting to asp.net api.
the problem am facing is whenever l post all the rows have the same value for
[{{$index}}].Name even if l select different values
Edit two
am not getting answers did l do it the wrong way /please even suggestion would help am two days stack on this. Help guys
angularjs
add a comment |
<tr ng-repeat="x in my_array">
<td>
<select name='[{{$index}}].Name' >
<option ng-repeat="sr in anotherArray" value="{{sr}}">
{{sr}}
</option>
</select>
</td>
</tr>
i have a table with rows populated by ng-repeat: my_array
there is another array : anotherArray
l want when the rows are repeated in angular for my_array to have its own value for [{{$index}}].Name to be based on the selected value for that particular row.
when l post the data to api [{{$index}}].Name will only have the same value even if l select different item for each rows.
l tried using ng-options as it was said its good for
of is there an easy way to get around it .
am populating the anotherArray and anotherArray
on different on same page but they are just an array with string values in it like as below
$scope.anotherArray= ;
$scope.add = function () {
$scope.errortext = "";
if (!$scope.addMe) { return; }
if ($scope.variants.indexOf($scope.addMe) == -1) {
$scope.anotherArray.push($scope.addMe);
}
}
the desired result is like
in image i_prepopulateOnRow1 ,i_prepopulateOnRow2 ...i_prepopulateOnRow upto Nth are add from anotherArray
when ever a new row from my_array is added it must have a select option for anotherArray thus in each row l can have value for i_prepopulateOnRow
the reason am using name as [{{$index}}].Name its becasue am posting to asp.net api.
the problem am facing is whenever l post all the rows have the same value for
[{{$index}}].Name even if l select different values
Edit two
am not getting answers did l do it the wrong way /please even suggestion would help am two days stack on this. Help guys
angularjs
add a comment |
<tr ng-repeat="x in my_array">
<td>
<select name='[{{$index}}].Name' >
<option ng-repeat="sr in anotherArray" value="{{sr}}">
{{sr}}
</option>
</select>
</td>
</tr>
i have a table with rows populated by ng-repeat: my_array
there is another array : anotherArray
l want when the rows are repeated in angular for my_array to have its own value for [{{$index}}].Name to be based on the selected value for that particular row.
when l post the data to api [{{$index}}].Name will only have the same value even if l select different item for each rows.
l tried using ng-options as it was said its good for
of is there an easy way to get around it .
am populating the anotherArray and anotherArray
on different on same page but they are just an array with string values in it like as below
$scope.anotherArray= ;
$scope.add = function () {
$scope.errortext = "";
if (!$scope.addMe) { return; }
if ($scope.variants.indexOf($scope.addMe) == -1) {
$scope.anotherArray.push($scope.addMe);
}
}
the desired result is like
in image i_prepopulateOnRow1 ,i_prepopulateOnRow2 ...i_prepopulateOnRow upto Nth are add from anotherArray
when ever a new row from my_array is added it must have a select option for anotherArray thus in each row l can have value for i_prepopulateOnRow
the reason am using name as [{{$index}}].Name its becasue am posting to asp.net api.
the problem am facing is whenever l post all the rows have the same value for
[{{$index}}].Name even if l select different values
Edit two
am not getting answers did l do it the wrong way /please even suggestion would help am two days stack on this. Help guys
angularjs
<tr ng-repeat="x in my_array">
<td>
<select name='[{{$index}}].Name' >
<option ng-repeat="sr in anotherArray" value="{{sr}}">
{{sr}}
</option>
</select>
</td>
</tr>
i have a table with rows populated by ng-repeat: my_array
there is another array : anotherArray
l want when the rows are repeated in angular for my_array to have its own value for [{{$index}}].Name to be based on the selected value for that particular row.
when l post the data to api [{{$index}}].Name will only have the same value even if l select different item for each rows.
l tried using ng-options as it was said its good for
of is there an easy way to get around it .
am populating the anotherArray and anotherArray
on different on same page but they are just an array with string values in it like as below
$scope.anotherArray= ;
$scope.add = function () {
$scope.errortext = "";
if (!$scope.addMe) { return; }
if ($scope.variants.indexOf($scope.addMe) == -1) {
$scope.anotherArray.push($scope.addMe);
}
}
the desired result is like
in image i_prepopulateOnRow1 ,i_prepopulateOnRow2 ...i_prepopulateOnRow upto Nth are add from anotherArray
when ever a new row from my_array is added it must have a select option for anotherArray thus in each row l can have value for i_prepopulateOnRow
the reason am using name as [{{$index}}].Name its becasue am posting to asp.net api.
the problem am facing is whenever l post all the rows have the same value for
[{{$index}}].Name even if l select different values
Edit two
am not getting answers did l do it the wrong way /please even suggestion would help am two days stack on this. Help guys
angularjs
angularjs
edited Nov 21 '18 at 9:10
Billy Watsy
asked Nov 21 '18 at 8:41
Billy WatsyBilly Watsy
186
186
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If you posting page on server side then HTML element name must be match with server class structure
Ex. Server class
public class otherClass
{
public int id { get; set; }
public string name { get; set; }
}
public class myclass
{
public string name { get; set; }
public List<string> nameList { get; set; }
public List<otherClass> otherList { get; set; }
}
then you HTML elment name should be like
<form method="post" action="http://localhost:56096/api/Values">
<div>
<input type="text" name="name" />
</div>
<div>
<ul>
<li>
<input type="text" name="nameList[0]" />
</li>
<li>
<input type="text" name="nameList[1]" />
</li>
<li>
<input type="text" name="nameList[2]" />
</li>
</ul>
</div>
<div>
<ul>
<li>
<input type="hidden" name="otherList[0].id" value="0" />
<input type="text" name="otherList[0].name" />
</li>
<li>
<input type="hidden" name="otherList[1].id" value="1" />
<input type="text" name="otherList[1].name" />
</li>
<li>
<input type="hidden" name="otherList[2].id" value="2" />
<input type="text" name="otherList[2].name" />
</li>
</ul>
</div>
<input type="submit" value="Submit" />
</form>
I home may you get help from this
Thanks
thanks man the Server side classes are fine tested using static data and working but the issue is on client side ,the selected values are in the html l cannot get the angular to have selected value for the different rows being posted
– Billy Watsy
Nov 21 '18 at 13:41
add a comment |
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
});
}
});
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%2f53408135%2fangular-get-selected-value-in-multiple-selects-inside-ng-repeat%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
If you posting page on server side then HTML element name must be match with server class structure
Ex. Server class
public class otherClass
{
public int id { get; set; }
public string name { get; set; }
}
public class myclass
{
public string name { get; set; }
public List<string> nameList { get; set; }
public List<otherClass> otherList { get; set; }
}
then you HTML elment name should be like
<form method="post" action="http://localhost:56096/api/Values">
<div>
<input type="text" name="name" />
</div>
<div>
<ul>
<li>
<input type="text" name="nameList[0]" />
</li>
<li>
<input type="text" name="nameList[1]" />
</li>
<li>
<input type="text" name="nameList[2]" />
</li>
</ul>
</div>
<div>
<ul>
<li>
<input type="hidden" name="otherList[0].id" value="0" />
<input type="text" name="otherList[0].name" />
</li>
<li>
<input type="hidden" name="otherList[1].id" value="1" />
<input type="text" name="otherList[1].name" />
</li>
<li>
<input type="hidden" name="otherList[2].id" value="2" />
<input type="text" name="otherList[2].name" />
</li>
</ul>
</div>
<input type="submit" value="Submit" />
</form>
I home may you get help from this
Thanks
thanks man the Server side classes are fine tested using static data and working but the issue is on client side ,the selected values are in the html l cannot get the angular to have selected value for the different rows being posted
– Billy Watsy
Nov 21 '18 at 13:41
add a comment |
If you posting page on server side then HTML element name must be match with server class structure
Ex. Server class
public class otherClass
{
public int id { get; set; }
public string name { get; set; }
}
public class myclass
{
public string name { get; set; }
public List<string> nameList { get; set; }
public List<otherClass> otherList { get; set; }
}
then you HTML elment name should be like
<form method="post" action="http://localhost:56096/api/Values">
<div>
<input type="text" name="name" />
</div>
<div>
<ul>
<li>
<input type="text" name="nameList[0]" />
</li>
<li>
<input type="text" name="nameList[1]" />
</li>
<li>
<input type="text" name="nameList[2]" />
</li>
</ul>
</div>
<div>
<ul>
<li>
<input type="hidden" name="otherList[0].id" value="0" />
<input type="text" name="otherList[0].name" />
</li>
<li>
<input type="hidden" name="otherList[1].id" value="1" />
<input type="text" name="otherList[1].name" />
</li>
<li>
<input type="hidden" name="otherList[2].id" value="2" />
<input type="text" name="otherList[2].name" />
</li>
</ul>
</div>
<input type="submit" value="Submit" />
</form>
I home may you get help from this
Thanks
thanks man the Server side classes are fine tested using static data and working but the issue is on client side ,the selected values are in the html l cannot get the angular to have selected value for the different rows being posted
– Billy Watsy
Nov 21 '18 at 13:41
add a comment |
If you posting page on server side then HTML element name must be match with server class structure
Ex. Server class
public class otherClass
{
public int id { get; set; }
public string name { get; set; }
}
public class myclass
{
public string name { get; set; }
public List<string> nameList { get; set; }
public List<otherClass> otherList { get; set; }
}
then you HTML elment name should be like
<form method="post" action="http://localhost:56096/api/Values">
<div>
<input type="text" name="name" />
</div>
<div>
<ul>
<li>
<input type="text" name="nameList[0]" />
</li>
<li>
<input type="text" name="nameList[1]" />
</li>
<li>
<input type="text" name="nameList[2]" />
</li>
</ul>
</div>
<div>
<ul>
<li>
<input type="hidden" name="otherList[0].id" value="0" />
<input type="text" name="otherList[0].name" />
</li>
<li>
<input type="hidden" name="otherList[1].id" value="1" />
<input type="text" name="otherList[1].name" />
</li>
<li>
<input type="hidden" name="otherList[2].id" value="2" />
<input type="text" name="otherList[2].name" />
</li>
</ul>
</div>
<input type="submit" value="Submit" />
</form>
I home may you get help from this
Thanks
If you posting page on server side then HTML element name must be match with server class structure
Ex. Server class
public class otherClass
{
public int id { get; set; }
public string name { get; set; }
}
public class myclass
{
public string name { get; set; }
public List<string> nameList { get; set; }
public List<otherClass> otherList { get; set; }
}
then you HTML elment name should be like
<form method="post" action="http://localhost:56096/api/Values">
<div>
<input type="text" name="name" />
</div>
<div>
<ul>
<li>
<input type="text" name="nameList[0]" />
</li>
<li>
<input type="text" name="nameList[1]" />
</li>
<li>
<input type="text" name="nameList[2]" />
</li>
</ul>
</div>
<div>
<ul>
<li>
<input type="hidden" name="otherList[0].id" value="0" />
<input type="text" name="otherList[0].name" />
</li>
<li>
<input type="hidden" name="otherList[1].id" value="1" />
<input type="text" name="otherList[1].name" />
</li>
<li>
<input type="hidden" name="otherList[2].id" value="2" />
<input type="text" name="otherList[2].name" />
</li>
</ul>
</div>
<input type="submit" value="Submit" />
</form>
I home may you get help from this
Thanks
answered Nov 21 '18 at 13:28
AjayAjay
662
662
thanks man the Server side classes are fine tested using static data and working but the issue is on client side ,the selected values are in the html l cannot get the angular to have selected value for the different rows being posted
– Billy Watsy
Nov 21 '18 at 13:41
add a comment |
thanks man the Server side classes are fine tested using static data and working but the issue is on client side ,the selected values are in the html l cannot get the angular to have selected value for the different rows being posted
– Billy Watsy
Nov 21 '18 at 13:41
thanks man the Server side classes are fine tested using static data and working but the issue is on client side ,the selected values are in the html l cannot get the angular to have selected value for the different rows being posted
– Billy Watsy
Nov 21 '18 at 13:41
thanks man the Server side classes are fine tested using static data and working but the issue is on client side ,the selected values are in the html l cannot get the angular to have selected value for the different rows being posted
– Billy Watsy
Nov 21 '18 at 13:41
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.
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%2f53408135%2fangular-get-selected-value-in-multiple-selects-inside-ng-repeat%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