角度预选

时间:2017-08-30 06:54:12

标签: angularjs angularjs-bootstrap

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

这是我的HTML

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

这是我的剧本

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

到目前为止,这是我试过的

HTML

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

在我的剧本中

{{1}}

它会预选,但问题是我无法选择其他选项

2 个答案:

答案 0 :(得分:0)

您应首先声明$scope.names然后向其添加productionType proerty。

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

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

&#13;
&#13;
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";
});
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试这个:

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