user5600308
user5600308

Reputation:

how to set the option of select dynamically via angularjs?

I found many question regarding to this topic and solutions to can not help; I have select like

   <select type="text" id="role" name="role" ng-model="role" ng-options="rol as rol.title for rol in rolelist" class="form-control" required>
        <option value="">Select Role</option>
    </select>
    <p class="ng-invalid"  ng-show="addForm.role.$error.required">Role need to selected</p>

and want to set the value of role model via angular js; i have done like this;

 $scope.role=$json.data.role_id;

didnot work for me?

Upvotes: 0

Views: 63

Answers (1)

Thomas Sawyer
Thomas Sawyer

Reputation: 39

ngOptions uses an expression to define what ngModel will be bound to. Since you have defined it as:

ng-options="rol as rol.title for rol in rolelist"

You are binding ngModel to a rol. Try this:

$scope.role=$json.data

Upvotes: 2

Related Questions