简体   繁体   English

角度预选

[英]Angular pre-selected

I have a modal that can edit. 我有一个可以编辑的模态。 But in my modal I cant pre-select. 但是在我的模态中,我无法预选。

This is my HTML 这是我的HTML

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

This is my Script 这是我的剧本

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

So far this is what I tried 到目前为止,这是我尝试过的

HTML 的HTML

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

In my script 在我的剧本中

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

It will pre selected but the problem is I cant select other options 它会预先选择,但问题是我无法选择其他选项

You should declare $scope.names firstly then add productionType proerty to it. 您应该首先声明$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM