我想设置选定的Audio
选项,但它不起作用。以下是我的HTML:
<form ng-app='test' ng-controller='testController'>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<select class="form-control" ng-model='event.type'>
<option disbaled> Select</option>
<option>IM</option>
<option>Audio</option>
</select>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
JS:
var testApp = angular.module('test', []);
testApp.controller('testController', function ($scope) {
$scope.event.type = 'Audio';//not working
});
有什么想法吗?
答案 0 :(得分:2)
使用
$ scope.event = {}如下所示
var testApp = angular.module('test', []);
testApp.controller('testController', function ($scope) {
$scope.event ={};
$scope.event.type = 'Audio';//not working
});
OR
testApp.controller('testController', function ($scope) {
$scope.event = {'type':'Audio'};//not working
});
答案 1 :(得分:2)
在声明对象事件时,代码中存在语法错误。右语法如下。
testApp.controller('testController', function ($scope) {
$scope.event ={};
$scope.event.type = 'Audio';//not working
});
您必须使用ng-selected指向angular来默认选择任何选项。
<option disbaled> Select</option>
<option>IM</option>
<option ng-selected="true">Audio</option>