Kishan Kishan - 2 months ago 15
AngularJS Question

ng-select is not working in angularjs?

I am facing some problem in drop down of angular js. Below is the html code

<select class="form-control" ng-init="projectName = options[0]" ng-model="projectName" name="projectName" ng-options="project.name for project in projectsList track by project.id" ng-class="{'submitted': submitted}" ng-selected="projectName" required>
<option value="">Select Project</option>
</select>


all the things coming fine.

But what i want is after selecting value from drop down we submit the form and in success am getting the value what i have selected. Now i want to set this value for the drop down, how to do it ?

In jquery it works

$("dropdown").val('successCallBackValue');


but in angular how to do it

Answer

After the sucess of the form submit just set the value in the dropdown model value as,

$scope.projectName = yourValue; // whatever selected value you are getting.

<select class="form-control" ng-init="projectName = options[0]" ng-model="projectName" name="projectName"  ng-options="project.name for project in projectsList track by project.id"  ng-class="{'submitted': submitted}"  required>
 <option value="">Select Project</option>
</select>