2016-11-04 6 views
0

ラベルと説明の2つの属性を持つオブジェクトのリストがあります。このリスト上のHTML Iサイクルに:私は何をしようとしているAngularJS-ng-repeat on objects

<select class="form-control" 
    ng-options="fid.label for fid in myFidList" 
    ng-model="fidSelected" 
    ng-change="setFidDescription()"/> 

私はオプションタグで選択したオブジェクトを取得する機能(setFidDescription)を呼んでいます。だから私は別のdivのそれぞれのdesciptionを変更することができます。これは機能していないようです:ng-modelは更新されていないようです。関数:

$scope.setFidDescription = function() { 
    console.log($scope.fidSelected); 
} 

このコードは空のオブジェクトを出力します。 私は何が欠けていますか?行く別の方法は私の選択の$インデックスを得ることができます。

さらに詳しい情報: JSON + console

アップデート: 私は私の問題を発見しました。説明についてはこちらをご覧ください:

AngularJS ngModel doesn't work inside a ui-bootstrap tabset

私の問題だったこと。

+0

jsonデータを投稿 – Sajeetharan

+0

console.log($ scope.fidSelected);でコンソールの正しいデータを取得していますか。 ? – Jigar7521

+0

いいえ、返信の属性が – Massimo

答えて

1

// Code goes here 
 

 
angular 
 
    .module('myApp', []) 
 

 
.controller('testController', ['$scope', 
 
    function($scope) { 
 

 
    $scope.myFidList = [{ 
 
     label: 'label1', 
 
    }, { 
 
     label: 'label2', 
 
    }] 
 

 
    $scope.setFidDescription = function() { 
 
     alert($scope.fidSelected.label); 
 
    } 
 

 
    } 
 
])
<!DOCTYPE html> 
 
<html data-ng-app="myApp"> 
 

 
<head> 
 
    <link rel="stylesheet" href="style.css"> 
 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> 
 
    <script src="script.js"></script> 
 
</head> 
 

 
<body data-ng-controller="testController"> 
 

 

 

 
    <select class="form-control" ng-options="fid.label for fid in myFidList" ng-model="fidSelected" ng-change="setFidDescription()"></select> 
 

 
</body> 
 

 
</html>

これはあなたを助けることを願っています。

+0

のthanskのオブジェクトを出力します。しかし、私は「未定義」になっています。 fidSelectedは空です。 – Massimo

+0

@Massimo、私の例でも? –

+0

はい、あなたのコード:[example](https://i.imgsafe.org/c3964603f4.png)。注:ng-repeatは正常に動作しています – Massimo