How to get and post 2 objects from ng-model?












0















I have here a sample document from mongodb named chapters:



{_id:5c014c999cc48c3b0057988b, chapter_name:"AB"}



Controller: here is my function to get the chapters, and function to post to another db:



.controller('regCtrl', function($http, $location, $timeout, User, Bloodbankchapter) {
Bloodbankchapter.getBloodbankchapters().then(function(data) {
app.bloodbankchapters = data.data.bloodbankchapters;
});

this.regUser = function(regData) {
User.create(app.regData).then(function(data) {});
};


Then in my front-end to register:



 <form name="regForm" ng-submit="register.regUser(regData); ">
<label>Chapter Name</label> <!--After I select the chapter name -->
<select ng-model="register.regData.branch" ng-options ="chapter._id as chapter.chapter_name for chapter in register.bloodbankchapters">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>

<label>Chapter ID</label> <!--chapter ID will appear here-->
<input type="text" ng-model="register.regData.branch_id" hidden>

<label>Chapter name</label> <!--How to make chapter name appear here?-->
<input type="text" ng-model="register.regData.branch_name" hidden>
<button ng-disabled="register.disabled" type="submit">Submit</button>
</form>


My problem here is after I selected the chapter name the second input was correct and it post the id into the db, but how can I get the chapter.name and post it to db?



I tried getting the text value from the select box and then appending it to a textbox like here: http://jsfiddle.net/kxqJN/, but when I register, the object id is being registered instead of chapter_name like this:



`{branch_id:5c014c999cc48c3b0057988b, branch_name:"5c014c999cc48c3b0057988b"}`


How can I display the name in the first box and the id in the second?



enter image description here










share|improve this question

























  • You seem to be using the _id for your options chapter_name values here: chapter._id as chapter.chapter_name. What does it look like if you replace it by chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id?

    – Kaddath
    10 hours ago











  • when I used chapter.chapter_name it shows the chapter_name, but I need to register both the id and the chapter_name

    – Jeremy Adrian de Vera
    10 hours ago
















0















I have here a sample document from mongodb named chapters:



{_id:5c014c999cc48c3b0057988b, chapter_name:"AB"}



Controller: here is my function to get the chapters, and function to post to another db:



.controller('regCtrl', function($http, $location, $timeout, User, Bloodbankchapter) {
Bloodbankchapter.getBloodbankchapters().then(function(data) {
app.bloodbankchapters = data.data.bloodbankchapters;
});

this.regUser = function(regData) {
User.create(app.regData).then(function(data) {});
};


Then in my front-end to register:



 <form name="regForm" ng-submit="register.regUser(regData); ">
<label>Chapter Name</label> <!--After I select the chapter name -->
<select ng-model="register.regData.branch" ng-options ="chapter._id as chapter.chapter_name for chapter in register.bloodbankchapters">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>

<label>Chapter ID</label> <!--chapter ID will appear here-->
<input type="text" ng-model="register.regData.branch_id" hidden>

<label>Chapter name</label> <!--How to make chapter name appear here?-->
<input type="text" ng-model="register.regData.branch_name" hidden>
<button ng-disabled="register.disabled" type="submit">Submit</button>
</form>


My problem here is after I selected the chapter name the second input was correct and it post the id into the db, but how can I get the chapter.name and post it to db?



I tried getting the text value from the select box and then appending it to a textbox like here: http://jsfiddle.net/kxqJN/, but when I register, the object id is being registered instead of chapter_name like this:



`{branch_id:5c014c999cc48c3b0057988b, branch_name:"5c014c999cc48c3b0057988b"}`


How can I display the name in the first box and the id in the second?



enter image description here










share|improve this question

























  • You seem to be using the _id for your options chapter_name values here: chapter._id as chapter.chapter_name. What does it look like if you replace it by chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id?

    – Kaddath
    10 hours ago











  • when I used chapter.chapter_name it shows the chapter_name, but I need to register both the id and the chapter_name

    – Jeremy Adrian de Vera
    10 hours ago














0












0








0








I have here a sample document from mongodb named chapters:



{_id:5c014c999cc48c3b0057988b, chapter_name:"AB"}



Controller: here is my function to get the chapters, and function to post to another db:



.controller('regCtrl', function($http, $location, $timeout, User, Bloodbankchapter) {
Bloodbankchapter.getBloodbankchapters().then(function(data) {
app.bloodbankchapters = data.data.bloodbankchapters;
});

this.regUser = function(regData) {
User.create(app.regData).then(function(data) {});
};


Then in my front-end to register:



 <form name="regForm" ng-submit="register.regUser(regData); ">
<label>Chapter Name</label> <!--After I select the chapter name -->
<select ng-model="register.regData.branch" ng-options ="chapter._id as chapter.chapter_name for chapter in register.bloodbankchapters">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>

<label>Chapter ID</label> <!--chapter ID will appear here-->
<input type="text" ng-model="register.regData.branch_id" hidden>

<label>Chapter name</label> <!--How to make chapter name appear here?-->
<input type="text" ng-model="register.regData.branch_name" hidden>
<button ng-disabled="register.disabled" type="submit">Submit</button>
</form>


My problem here is after I selected the chapter name the second input was correct and it post the id into the db, but how can I get the chapter.name and post it to db?



I tried getting the text value from the select box and then appending it to a textbox like here: http://jsfiddle.net/kxqJN/, but when I register, the object id is being registered instead of chapter_name like this:



`{branch_id:5c014c999cc48c3b0057988b, branch_name:"5c014c999cc48c3b0057988b"}`


How can I display the name in the first box and the id in the second?



enter image description here










share|improve this question
















I have here a sample document from mongodb named chapters:



{_id:5c014c999cc48c3b0057988b, chapter_name:"AB"}



Controller: here is my function to get the chapters, and function to post to another db:



.controller('regCtrl', function($http, $location, $timeout, User, Bloodbankchapter) {
Bloodbankchapter.getBloodbankchapters().then(function(data) {
app.bloodbankchapters = data.data.bloodbankchapters;
});

this.regUser = function(regData) {
User.create(app.regData).then(function(data) {});
};


Then in my front-end to register:



 <form name="regForm" ng-submit="register.regUser(regData); ">
<label>Chapter Name</label> <!--After I select the chapter name -->
<select ng-model="register.regData.branch" ng-options ="chapter._id as chapter.chapter_name for chapter in register.bloodbankchapters">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>

<label>Chapter ID</label> <!--chapter ID will appear here-->
<input type="text" ng-model="register.regData.branch_id" hidden>

<label>Chapter name</label> <!--How to make chapter name appear here?-->
<input type="text" ng-model="register.regData.branch_name" hidden>
<button ng-disabled="register.disabled" type="submit">Submit</button>
</form>


My problem here is after I selected the chapter name the second input was correct and it post the id into the db, but how can I get the chapter.name and post it to db?



I tried getting the text value from the select box and then appending it to a textbox like here: http://jsfiddle.net/kxqJN/, but when I register, the object id is being registered instead of chapter_name like this:



`{branch_id:5c014c999cc48c3b0057988b, branch_name:"5c014c999cc48c3b0057988b"}`


How can I display the name in the first box and the id in the second?



enter image description here







node.js angularjs mongodb mean-stack






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 10 hours ago







Jeremy Adrian de Vera

















asked 11 hours ago









Jeremy Adrian de VeraJeremy Adrian de Vera

426




426













  • You seem to be using the _id for your options chapter_name values here: chapter._id as chapter.chapter_name. What does it look like if you replace it by chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id?

    – Kaddath
    10 hours ago











  • when I used chapter.chapter_name it shows the chapter_name, but I need to register both the id and the chapter_name

    – Jeremy Adrian de Vera
    10 hours ago



















  • You seem to be using the _id for your options chapter_name values here: chapter._id as chapter.chapter_name. What does it look like if you replace it by chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id?

    – Kaddath
    10 hours ago











  • when I used chapter.chapter_name it shows the chapter_name, but I need to register both the id and the chapter_name

    – Jeremy Adrian de Vera
    10 hours ago

















You seem to be using the _id for your options chapter_name values here: chapter._id as chapter.chapter_name. What does it look like if you replace it by chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id?

– Kaddath
10 hours ago





You seem to be using the _id for your options chapter_name values here: chapter._id as chapter.chapter_name. What does it look like if you replace it by chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id?

– Kaddath
10 hours ago













when I used chapter.chapter_name it shows the chapter_name, but I need to register both the id and the chapter_name

– Jeremy Adrian de Vera
10 hours ago





when I used chapter.chapter_name it shows the chapter_name, but I need to register both the id and the chapter_name

– Jeremy Adrian de Vera
10 hours ago












2 Answers
2






active

oldest

votes


















1














I bet you haven't tried what i suggested in the comments: chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id will lead you to have both values in your model:






angular.module('selectExample', )
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
bloodbankchapters: [
{_id:'5c014c999cc48c3b0057988b', chapter_name:"AB"},
{_id:'5c014c999cc48c3b0057988c', chapter_name:"A"},
],
};
}]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="register.regData.branch" ng-options ="chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>
<div>{{register.regData.branch}}</div>
</div>








share|improve this answer
























  • now its showing, but this shows the whole document: here is what I get{_id":"5c014c999cc48c3b0057988b","chapter_name":"Caloocan","chapter_address":"7th Ave. Grace Park, Caloocan City","chapter_email":"caloocan@redcross.org.ph","chapter_category":"Blood Collecting Unit/Blood Station","chapter_id":"111"}

    – Jeremy Adrian de Vera
    10 hours ago













  • is it possible to output only a certain field like chapter.chapter_id and chapter.chapter_name

    – Jeremy Adrian de Vera
    10 hours ago











  • oh never mind, it's working now thanks sir!

    – Jeremy Adrian de Vera
    10 hours ago











  • you're welcome! You can still use a pipe to modify objects in the ng-repeat (i think) and keep only what you want, but i'm no specialist of angular pipes. As a workaroud, i would use a function to get just what you want, something like ` in getBloodbankchapters()`, but that's because i'm no specialist :P

    – Kaddath
    10 hours ago





















0














Try this way, you will get selected chapter object inside register.regData.branch



<select ng-model="register.regData.branch" ng-options ="chapter as chapter.value for chapter in register.bloodbankchapters">





share|improve this answer
























  • does not work i need to display the id in the second textbox

    – Jeremy Adrian de Vera
    10 hours ago











  • to display branch_name and branch_id i think you need to use ng-model="register.regData.branch.branch_id" and ng-model="register.regData.branch.branch_name"

    – Mohit Raiyani
    10 hours ago













  • it is possible to bind this in one input?

    – Jeremy Adrian de Vera
    10 hours ago











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%2f54249907%2fhow-to-get-and-post-2-objects-from-ng-model%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I bet you haven't tried what i suggested in the comments: chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id will lead you to have both values in your model:






angular.module('selectExample', )
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
bloodbankchapters: [
{_id:'5c014c999cc48c3b0057988b', chapter_name:"AB"},
{_id:'5c014c999cc48c3b0057988c', chapter_name:"A"},
],
};
}]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="register.regData.branch" ng-options ="chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>
<div>{{register.regData.branch}}</div>
</div>








share|improve this answer
























  • now its showing, but this shows the whole document: here is what I get{_id":"5c014c999cc48c3b0057988b","chapter_name":"Caloocan","chapter_address":"7th Ave. Grace Park, Caloocan City","chapter_email":"caloocan@redcross.org.ph","chapter_category":"Blood Collecting Unit/Blood Station","chapter_id":"111"}

    – Jeremy Adrian de Vera
    10 hours ago













  • is it possible to output only a certain field like chapter.chapter_id and chapter.chapter_name

    – Jeremy Adrian de Vera
    10 hours ago











  • oh never mind, it's working now thanks sir!

    – Jeremy Adrian de Vera
    10 hours ago











  • you're welcome! You can still use a pipe to modify objects in the ng-repeat (i think) and keep only what you want, but i'm no specialist of angular pipes. As a workaroud, i would use a function to get just what you want, something like ` in getBloodbankchapters()`, but that's because i'm no specialist :P

    – Kaddath
    10 hours ago


















1














I bet you haven't tried what i suggested in the comments: chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id will lead you to have both values in your model:






angular.module('selectExample', )
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
bloodbankchapters: [
{_id:'5c014c999cc48c3b0057988b', chapter_name:"AB"},
{_id:'5c014c999cc48c3b0057988c', chapter_name:"A"},
],
};
}]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="register.regData.branch" ng-options ="chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>
<div>{{register.regData.branch}}</div>
</div>








share|improve this answer
























  • now its showing, but this shows the whole document: here is what I get{_id":"5c014c999cc48c3b0057988b","chapter_name":"Caloocan","chapter_address":"7th Ave. Grace Park, Caloocan City","chapter_email":"caloocan@redcross.org.ph","chapter_category":"Blood Collecting Unit/Blood Station","chapter_id":"111"}

    – Jeremy Adrian de Vera
    10 hours ago













  • is it possible to output only a certain field like chapter.chapter_id and chapter.chapter_name

    – Jeremy Adrian de Vera
    10 hours ago











  • oh never mind, it's working now thanks sir!

    – Jeremy Adrian de Vera
    10 hours ago











  • you're welcome! You can still use a pipe to modify objects in the ng-repeat (i think) and keep only what you want, but i'm no specialist of angular pipes. As a workaroud, i would use a function to get just what you want, something like ` in getBloodbankchapters()`, but that's because i'm no specialist :P

    – Kaddath
    10 hours ago
















1












1








1







I bet you haven't tried what i suggested in the comments: chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id will lead you to have both values in your model:






angular.module('selectExample', )
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
bloodbankchapters: [
{_id:'5c014c999cc48c3b0057988b', chapter_name:"AB"},
{_id:'5c014c999cc48c3b0057988c', chapter_name:"A"},
],
};
}]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="register.regData.branch" ng-options ="chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>
<div>{{register.regData.branch}}</div>
</div>








share|improve this answer













I bet you haven't tried what i suggested in the comments: chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id will lead you to have both values in your model:






angular.module('selectExample', )
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
bloodbankchapters: [
{_id:'5c014c999cc48c3b0057988b', chapter_name:"AB"},
{_id:'5c014c999cc48c3b0057988c', chapter_name:"A"},
],
};
}]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="register.regData.branch" ng-options ="chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>
<div>{{register.regData.branch}}</div>
</div>








angular.module('selectExample', )
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
bloodbankchapters: [
{_id:'5c014c999cc48c3b0057988b', chapter_name:"AB"},
{_id:'5c014c999cc48c3b0057988c', chapter_name:"A"},
],
};
}]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="register.regData.branch" ng-options ="chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>
<div>{{register.regData.branch}}</div>
</div>





angular.module('selectExample', )
.controller('ExampleController', ['$scope', function($scope) {
$scope.register = {
regData: {
branch: {},
},
bloodbankchapters: [
{_id:'5c014c999cc48c3b0057988b', chapter_name:"AB"},
{_id:'5c014c999cc48c3b0057988c', chapter_name:"A"},
],
};
}]);

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="register.regData.branch" ng-options ="chapter.chapter_name for chapter in register.bloodbankchapters track by chapter._id">
<option ng-repeat="chapter in register.bloodbankchapters" >{{chapter.chapter_name}}</option>
</select>
<div>{{register.regData.branch}}</div>
</div>






share|improve this answer












share|improve this answer



share|improve this answer










answered 10 hours ago









KaddathKaddath

2,4871516




2,4871516













  • now its showing, but this shows the whole document: here is what I get{_id":"5c014c999cc48c3b0057988b","chapter_name":"Caloocan","chapter_address":"7th Ave. Grace Park, Caloocan City","chapter_email":"caloocan@redcross.org.ph","chapter_category":"Blood Collecting Unit/Blood Station","chapter_id":"111"}

    – Jeremy Adrian de Vera
    10 hours ago













  • is it possible to output only a certain field like chapter.chapter_id and chapter.chapter_name

    – Jeremy Adrian de Vera
    10 hours ago











  • oh never mind, it's working now thanks sir!

    – Jeremy Adrian de Vera
    10 hours ago











  • you're welcome! You can still use a pipe to modify objects in the ng-repeat (i think) and keep only what you want, but i'm no specialist of angular pipes. As a workaroud, i would use a function to get just what you want, something like ` in getBloodbankchapters()`, but that's because i'm no specialist :P

    – Kaddath
    10 hours ago





















  • now its showing, but this shows the whole document: here is what I get{_id":"5c014c999cc48c3b0057988b","chapter_name":"Caloocan","chapter_address":"7th Ave. Grace Park, Caloocan City","chapter_email":"caloocan@redcross.org.ph","chapter_category":"Blood Collecting Unit/Blood Station","chapter_id":"111"}

    – Jeremy Adrian de Vera
    10 hours ago













  • is it possible to output only a certain field like chapter.chapter_id and chapter.chapter_name

    – Jeremy Adrian de Vera
    10 hours ago











  • oh never mind, it's working now thanks sir!

    – Jeremy Adrian de Vera
    10 hours ago











  • you're welcome! You can still use a pipe to modify objects in the ng-repeat (i think) and keep only what you want, but i'm no specialist of angular pipes. As a workaroud, i would use a function to get just what you want, something like ` in getBloodbankchapters()`, but that's because i'm no specialist :P

    – Kaddath
    10 hours ago



















now its showing, but this shows the whole document: here is what I get{_id":"5c014c999cc48c3b0057988b","chapter_name":"Caloocan","chapter_address":"7th Ave. Grace Park, Caloocan City","chapter_email":"caloocan@redcross.org.ph","chapter_category":"Blood Collecting Unit/Blood Station","chapter_id":"111"}

– Jeremy Adrian de Vera
10 hours ago







now its showing, but this shows the whole document: here is what I get{_id":"5c014c999cc48c3b0057988b","chapter_name":"Caloocan","chapter_address":"7th Ave. Grace Park, Caloocan City","chapter_email":"caloocan@redcross.org.ph","chapter_category":"Blood Collecting Unit/Blood Station","chapter_id":"111"}

– Jeremy Adrian de Vera
10 hours ago















is it possible to output only a certain field like chapter.chapter_id and chapter.chapter_name

– Jeremy Adrian de Vera
10 hours ago





is it possible to output only a certain field like chapter.chapter_id and chapter.chapter_name

– Jeremy Adrian de Vera
10 hours ago













oh never mind, it's working now thanks sir!

– Jeremy Adrian de Vera
10 hours ago





oh never mind, it's working now thanks sir!

– Jeremy Adrian de Vera
10 hours ago













you're welcome! You can still use a pipe to modify objects in the ng-repeat (i think) and keep only what you want, but i'm no specialist of angular pipes. As a workaroud, i would use a function to get just what you want, something like ` in getBloodbankchapters()`, but that's because i'm no specialist :P

– Kaddath
10 hours ago







you're welcome! You can still use a pipe to modify objects in the ng-repeat (i think) and keep only what you want, but i'm no specialist of angular pipes. As a workaroud, i would use a function to get just what you want, something like ` in getBloodbankchapters()`, but that's because i'm no specialist :P

– Kaddath
10 hours ago















0














Try this way, you will get selected chapter object inside register.regData.branch



<select ng-model="register.regData.branch" ng-options ="chapter as chapter.value for chapter in register.bloodbankchapters">





share|improve this answer
























  • does not work i need to display the id in the second textbox

    – Jeremy Adrian de Vera
    10 hours ago











  • to display branch_name and branch_id i think you need to use ng-model="register.regData.branch.branch_id" and ng-model="register.regData.branch.branch_name"

    – Mohit Raiyani
    10 hours ago













  • it is possible to bind this in one input?

    – Jeremy Adrian de Vera
    10 hours ago
















0














Try this way, you will get selected chapter object inside register.regData.branch



<select ng-model="register.regData.branch" ng-options ="chapter as chapter.value for chapter in register.bloodbankchapters">





share|improve this answer
























  • does not work i need to display the id in the second textbox

    – Jeremy Adrian de Vera
    10 hours ago











  • to display branch_name and branch_id i think you need to use ng-model="register.regData.branch.branch_id" and ng-model="register.regData.branch.branch_name"

    – Mohit Raiyani
    10 hours ago













  • it is possible to bind this in one input?

    – Jeremy Adrian de Vera
    10 hours ago














0












0








0







Try this way, you will get selected chapter object inside register.regData.branch



<select ng-model="register.regData.branch" ng-options ="chapter as chapter.value for chapter in register.bloodbankchapters">





share|improve this answer













Try this way, you will get selected chapter object inside register.regData.branch



<select ng-model="register.regData.branch" ng-options ="chapter as chapter.value for chapter in register.bloodbankchapters">






share|improve this answer












share|improve this answer



share|improve this answer










answered 10 hours ago









Mohit RaiyaniMohit Raiyani

112




112













  • does not work i need to display the id in the second textbox

    – Jeremy Adrian de Vera
    10 hours ago











  • to display branch_name and branch_id i think you need to use ng-model="register.regData.branch.branch_id" and ng-model="register.regData.branch.branch_name"

    – Mohit Raiyani
    10 hours ago













  • it is possible to bind this in one input?

    – Jeremy Adrian de Vera
    10 hours ago



















  • does not work i need to display the id in the second textbox

    – Jeremy Adrian de Vera
    10 hours ago











  • to display branch_name and branch_id i think you need to use ng-model="register.regData.branch.branch_id" and ng-model="register.regData.branch.branch_name"

    – Mohit Raiyani
    10 hours ago













  • it is possible to bind this in one input?

    – Jeremy Adrian de Vera
    10 hours ago

















does not work i need to display the id in the second textbox

– Jeremy Adrian de Vera
10 hours ago





does not work i need to display the id in the second textbox

– Jeremy Adrian de Vera
10 hours ago













to display branch_name and branch_id i think you need to use ng-model="register.regData.branch.branch_id" and ng-model="register.regData.branch.branch_name"

– Mohit Raiyani
10 hours ago







to display branch_name and branch_id i think you need to use ng-model="register.regData.branch.branch_id" and ng-model="register.regData.branch.branch_name"

– Mohit Raiyani
10 hours ago















it is possible to bind this in one input?

– Jeremy Adrian de Vera
10 hours ago





it is possible to bind this in one input?

– Jeremy Adrian de Vera
10 hours ago


















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%2f54249907%2fhow-to-get-and-post-2-objects-from-ng-model%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

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage