2016-06-01 3 views
0

<select> AngularJSとNG-選択

var app = angular.module("partnerModule", []); 
app.controller("SimpleController", function($scope) { 
    $scope.item = {category: {name:'Cat1', id: '1'}, name : "Item name"}; 
    $scope.categories = [{name:'Cat1', id: '1'}, {name: 'Cat2', id: '2'}, {name:'Cat3', id: '3'}]; 
}); 

を、私は、フォームが表示されたときに、すでに "CAT1" のオプションを設定しているしたいと思います。それはこれが動作する

答えて

1

を動作しませんでした両方<select><option>タグについて

ng-selected="item.category.id == category.id" 

:私はこのような何かを追加しようとしました JS

でHTML

<div ng-controller="SimpleController"> 
    <select ng-model="item.category" ng-options="category as category.name for category in categories track by category.id"> 
    </select> 
    <br />Item: {{item | json}} 
</div> 

var app = angular.module("partnerModule", []); 
app.controller("SimpleController", function($scope) { 
    $scope.item = {category: {name:'Cat1', id: '1'}, name : "Item name"}; 
    $scope.categories = [{name:'Cat1', id: '1'}, {name: 'Cat2', id: '2'}, {name:'Cat3', id: '3'}]; 
}); 
関連する問題