Take the 2-minute tour ×

Here is my form's select control:

<select ng-model="truckMfg.truckMfgs" ng-options="truckMfg.Name for truckMfg in truckMfgs">
   <option value="" selected>Select Truck Manufacturer ..</option>  

I have a modal that allows the user to add Mfgs not already in the table. Here is my controller:

function TruckMfgCtrl($scope, $routeParams, $http, API, $location)  {

$scope.truckMfgs = API.GetTruckMfgs(); // <-- this works at initialization

$scope.save = function () {
    $http.post('/api/TruckMfgs/', $scope.truckMfg)  // data does get saved corectly
        .success(function () {
        .error(function (data) {

    setTimeout(function () {
        $scope.truckMfgs = API.GetTruckMfgs(); // <-- this is not working
    }, 1000);


What I am trying to accomplish:

After the user adds a new manufacturer and the modal closes, I want the select control to be updated to the new list of manufacturers. The addtl mfg is being added to the table but it is not appearing in the select control. Refreshing the form will show the new data but that of course is not what I want.

Any ideas?

Mark Rajcok

I appreciate your help. I tried this and it did not work:

$scope.save = function () {
        .success(function () {
        .error(function (data) {

Respectfully, could you show me the code you are recommending? Thanks

(PS: Checked out your profile, I too drink cawfee and take my dawghter to the mawl, but not in Nork) :)

share|improve this question
What you tried looks correct. If you log $scope.truckMfgs after adding $scope.truckMfg, does it look correct? If so, then I'd need to see more of your code to help further. I live in central NJ, so I don't have the accent :) –  Mark Rajcok Mar 2 '13 at 22:39
sorry, try push() instead of append() –  Mark Rajcok Mar 2 '13 at 22:45
no errors with push. However, when the modal closes and I look at the TruckMfgs dropdown, the newly created Mfg is not there, only when I refresh the page - again, something I do not want to do. –  Bye Mar 2 '13 at 22:47
Can you put up a fiddle or plunker? (Don't worry about the server interface not working, just hardcode one sample truckMfg object in your controller. I'll mock it out the post() call with a $timeout.) –  Mark Rajcok Mar 2 '13 at 22:52
show 2 more comments

1 Answer

up vote 1 down vote accepted

I don't see any need to call GetTruckMfgs() in save(), because you already have the data you need to add to your truckMfgs list. So instead, have save() add/append $scope.truckMfg to $scope.truckMfgs. This way you avoid another trip to the server.

You could do this in your success() callback, if you want to ensure that the data was successfully post'ed before you update your select list. If you want your UI to update faster (i.e., be more responsive), you could do this before (or after) the post() call in your save function, but then handle any errors in your error callback (e.g., remove the item from the select list if post() failed).

share|improve this answer
Mark see above. Thanks –  Bye Mar 2 '13 at 22:24
Mark, after placing the input form to add the addtl Mfg right on the main form and not the modal, it updated scope immediately, so something is wrong with the modal but your code solution was sound. -- Thanks! –  Bye Mar 2 '13 at 23:10
add comment

Your Answer


