1

It is simple i know but just bugging me i got the following code

<label>Role</label><div>
<select ng-change="save()" ng-model="frm.TypeID">
    <option ng-value="">Select Role</option>
    <option ng-value="1" value="1">Admin</option>
    <option ng-value="3" value="3">User</option>
    <option ng-value="2" value="2">Guest</option>
</select>

I get the ng-value from the database but can not update it via the controller so how can i do something like

angular.controller('testCtrl',['$scope', function($scope){
 $scope.select=function(){
    $scope.frm.TypeID = 3;
}
}]);

Thanks

1
  • It's not clear what you need to do, and whats the problem with the actual code... Commented Oct 17, 2015 at 22:58

1 Answer 1

2

Use ng-options:

Template

<select ng-model="frm.TypeID" ng-options="role.id as role.label for role in roles">
    <option ng-value="">Select Role</option>
</select>

Controller

$scope.roles = [
    {id: 1, label: 'Admin'},
    {id: 2, label: 'User'},
    {id: 3, label: 'Guest'}
];

$scope.frm = {
    TypeID: 3
};

// fetch value from database then update value
fetchData().then(function (id) {
    $scope.frm.TypeID = id;
} 

See fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.