我正在尝试使用角度js中的ng-init为选择框的选项设置默认值,但它不起作用。这是我到目前为止编写的代码。
var app = angular.module("myApp", [])
app.controller("mainController", ["$scope", function($scope){
$scope.myoptions = "";
$scope.mainList = [
"firstOption",
"secondOption",
"thirdOption"
]
}]);
select{
width:50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<select ng-controller="mainController" ng-options="options as options for options in mainList" ng-model="myoptions" nginit="myoptions=mainList[1]">
</select>
</body>
请帮帮我。在此先感谢:)
答案 0 :(得分:3)
你有
CFBundleTypeIconFiles
应该是
nginit
答案 1 :(得分:2)
count_special
答案 2 :(得分:2)
{j}
中ng-init
没有nginit
指令
var app = angular.module("myApp", [])
app.controller("mainController", ["$scope", function($scope){
$scope.myoptions = "";
$scope.mainList = [
"firstOption",
"secondOption",
"thirdOption"
]
}]);
select{
width:50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<select ng-controller="mainController" ng-options="options as options for options in mainList" ng-model="myoptions" ng-init="myoptions=mainList[1]">
</select>
</body>
答案 3 :(得分:1)
更改nginit="myoptions = mainList[1]"
到ng-init="myoptions = mainList[1]"
var app = angular.module("myApp", [])
app.controller("mainController", ["$scope", function($scope){
$scope.mainList = [
"firstOption",
"secondOption",
"thirdOption"
]
}]);
select{
width:50%;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<select ng-controller="mainController" ng-options="options as options for options in mainList" ng-model="myoptions" ng-init="myoptions = mainList[1]">
</select>
</body>