Search code examples
javascriptangularjsangularjs-scope

ng-model is not updating in select (ng-options)


I need to bind an array into select control and save the selected option to another variable . Please check this plunker code for whole problem and code

 $scope.actions = [{ name: "alert", id: 1 }, { name: "drop", id: 2 }];
    $scope.raction = $scope.actions[0]; // Keeping first element to model


  //Mark-ups///
    <select class="form-control"
     ng-model="raction" ng-options="action.name for action in actions"   ></select>

http://plnkr.co/edit/NTnxAuxwxJrIIeS4sWlM?p=preview


Solution

  • Problem is in your scope binding. Change your code like this:

    $scope.showit = function() {
        alert(formentityModel.$scope.raction.name);   
    }
    

    This was an angular-strap issue, you can read more here :

    A new scope is created regardless of the scope passed in. Variables assigned to the scope in the controller will be visible using the $parent variable.