LoginSignup
11
11

More than 5 years have passed since last update.

Angular.jsでプルダウンにデータバインド

Last updated at Posted at 2012-12-26

例えば以下のようなjson形式のデータが返ってくるとする。
dataList: [{key: "1",value: "テスト1"},{key: "2",value: "テスト2"}]

★javaScript側(※コントローラの中)

var SampleCtrl = function() {
         $scope.results = dataList
}

★HTML側

<select id="sample_id" ng-model="samle_id" 
        ng-options="result.key as result.value for result in results"  ng-change="doEventSearch()">

※ HTML側にAngular.jsと読みこんでコントローラの定義などお忘れなく

上記のようにHTML側の変数名"results"にAPIから取得したjsonデータがセットされてプルダウンにデータバインドすることができる。

順番が逆になってしまったけど、次の投稿でAngular.jsの導入方法についてまとめようと思う。

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11