0

I have data like this :

EDIT

I solved my problem by change to acti[0] . But now I get wrong value in select . How can I solve this

1
  • would value not be k? Commented Jun 6, 2017 at 9:40

2 Answers 2

2

You just miss the , symbol between each element in your object.

$scope.provinces = [ { 00844:"Hà Nội", 00848:"TPHCM", 008418:"Hòa Bình", 008419:"Hà Giang", 008420:"Lào Cai", 008422:"Sơn La", 008425:"Lạng Sơn", 008426:"Cao Bằng", 008427:"Tuyên Quang", 008429:"Yên Bái", 008430:"Ninh Bình", 008431:"Hải Phòng" } ]

Sign up to request clarification or add additional context in comments.

Comments

1

Access the first object of the array

ng-options ="k as v for (k,v) in provinces[0]

demo

angular.module("app",[])
.controller("ctrl",function($scope){

$scope.provinces =    [
    {
    00844:"Hà Nội",
    00848:"TPHCM",
    008418:"Hòa Bình",
    008419:"Hà Giang",
    008420:"Lào Cai",
    008422:"Sơn La",
    008425:"Lạng Sơn",
    008426:"Cao Bằng",
    008427:"Tuyên Quang",
    008429:"Yên Bái",
    008430:"Ninh Bình",
    008431:"Hải Phòng"
    }
    ]
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <select ng-model="formDataAddress.province"
                ng-options ="k as v for (k,v) in provinces[0]"  ng-selected="">
                 </select>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.