I am almost new to AngularJS, and I am using a select tag for selection . What I want is to have a default value (i.e admin) for my select tag to define the role of my user which are agent and admin
Here is my HTML codes:
<div class="row">
<div class = "form-group col-xs-12 col-md-6">
<label>
Role
</label>
<select class="form-control" ng-options="value for value in roles" ng-model="newStaff.role_name='agent'"></select>
</div>
</div>
and here is my controller codes:
controllers.controller('StaffMembersNewCtrl', function ($scope, StaffMembers, $state) {
$scope.roles = ['admin', 'agent'];
StaffMembers.query(function(responce) {
$scope.staffs = responce;
});
$scope.SaveNewStaffMember = function(){
StaffMembers.save($scope.newStaff, function(){
$scope.addAlert('success', 'New staff member was added successfully!');
$state.go('staffMembersSettings');
});
};
});
It seems working, I have a default value, and data is bind, but there is an error in browser.
Error: [ngModel:nonassign] Expression 'newStaff.role_name='agent'' is non-assignable. Element: <select class="form-control ng-pristine ng-untouched ng-valid" ng-options="value for value in roles" ng-model="newStaff.role_name='agent'">
I understand this error, but I can not find an alternative solution for my problem which is putting a default value for my select tag.