我在angular js下拉菜单中遇到一些问题。以下是html代码

<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>


一切都很好。

但是我想要的是从下拉列表中选择值之后,我们提交表单,成功获取了我选择的值。现在我想为下拉菜单设置此值,怎么做?

在jQuery中工作

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


但在角度上怎么做

最佳答案

表单成功提交后,只需将下拉模型值中的值设置为

$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>

关于javascript - ng-select在angularjs中不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39769736/

10-09 09:06