我有一个像这样的Select元素
<select class="form-control" id="designation" ng-model="employee.designation" ng-init="select Designation = options[0]" ng-options="d for d in designations" required></select>
现在我想设置此元素的初始值,例如&#39;选择指定&#39;成为默认值。我怎么能实现这个目标?我能够绑定值,但我无法设置默认值,任何人都可以帮助我!!!
控制器代码是这个
(function () {
var app = angular.module('mainApp', []);
app.controller('employeeCtrl', ['$scope', '$http', function ($scope, $http) {
this.employee = {};
$http.get('/Data/Designation.json').success(function (data) {
debugger;
$scope.designations = data;
}).error(function () {
alert('error !!!');
});
$scope.formSubmit = function () {
debugger;
};
}]);
})();
答案 0 :(得分:0)
仅针对那些陷入同样情况的人,我通过在文件中添加默认值来解决问题,我从中检索数据并使用ng-init标签,如下所示
ng-init="designations[0]"