[英]Angular pre-selected
我有一个可以编辑的模态。 但是在我的模态中,我无法预选。
这是我的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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.