0

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

这是我的 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";

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

4

2 回答 2

0

您应该$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>

于 2017-08-30T06:55:21.707 回答
0

尝试这个:

<select ng-model='names.productionType' ng-value="data.productionType" ng-options="data.productionType for data in productionType"></select>
于 2017-08-30T07:31:01.383 回答