角度预先选定



我有一个可以编辑的模态。但在我的模态中,我无法预先选择。

这是我的HTML

<select ng-model='names.productionType' ng-options="data for data in productionType"></select>

这是我的脚本

$scope.productionType =[
"Article LP Composition",
"Normal LP Composition",
"Reading Material",
"Transcribed Manuscript",
"LP Production"
];

到目前为止,这就是我尝试的

HTML

<select ng-model='editable.productionType' ng-options="data for data in productionType" ng-selected="editable.productionType='{{names.production_type}}'"></select>

在我的脚本中

$scope.names.productionType = "Normal LP Composition";

它将被预先选择,但问题是我无法选择其他选项

您应该首先声明$scope.names,然后向其添加productionType项目。

<select ng-model='names.productionType' ng-options="data as data for data in productionType">
</select>
$scope.names ={};
$scope.names.productionType = "Normal LP Composition";

var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.productionType = [
"Article LP Composition",
"Normal LP Composition",
"Reading Material",
"Transcribed Manuscript",
"LP Production"
];
$scope.names = {};
$scope.names.productionType = "Normal LP Composition";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-filter/0.4.7/angular-filter.js"></script>
<div ng-app="plunker" ng-controller="MainCtrl">
<select ng-model='names.productionType' ng-options="data as data for data in productionType">
</select>
{{names.productionType}}
</div>

试试这个:

<select ng-model='names.productionType' ng-value="data.productionType" ng-options="data.productionType for data in productionType"></select>

相关内容

  • 没有找到相关文章

最新更新