How to bind dropdown control in edit mode?

前端 未结 2 1444
感情败类
感情败类 2021-01-14 13:21

I am having a list of country along with its corresponding states.

Now i want to bind the country and state value in dropdown control when open in edit mode.

2条回答
  •  滥情空心
    2021-01-14 13:44

    Here is what you wanted you could use ng-options for both select box for states & countries.

    HTML

    
        

    {{ friend.Country.Name }}

    {{friend.State.Name }}

    Controller

    $scope.countries = [{
        "Id": 1,
        "Name": "America",
    }, {
        "Id": 2,
        "Name": "Australia",
    }, {
        "Id": 3,
        "Name": "london",
    }];
    
    $scope.states = [{
        Id: 1,
        CountryId: 1,
        Name: "Chicago",
    }, {
        Id: 2,
        CountryId: 2,
        Name: "sydney",
    }, {
        Id: 3,
        CountryId: 3,
        Name: "abc",
    }];
    

    Working Fiddle

    Note

    Used track by id for selecting option on load as suggest in this github issue

提交回复
热议问题