2017-08-30 46 views
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"; 

它會預先選定的,但問題是我不能選擇其他選項

+0

你'NG-選擇= 「editable.productionType = '{{names.production_type}}'」'不應該有括號。你可以刪除整個'ng-selected',因爲angular會發現你的'ng-model'等於其中一個選項,然後選擇它。看到[這個jsfiddle](https://jsfiddle.net/b6cu3u8s/) – devqon

+0

@devqon但是當我改變預先選擇提交時,它不會給我提交模態的新值。 –

回答

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"; 

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>

+0

$ scope.names在模態中已經聲明瞭什麼,所以它就像這樣'var productionModal = function($ scope,$ uibModalInstance,$ uibModal,$ http,items){$ scope.names = items;}' –

+0

爲什麼' $ scope.names = items;'? –

+0

nvrm關於那一個,但問題是當我要選擇其他選項時,它總是返回到**「普通LP組合」**當我要提交它時 –

0

試試這個:

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