AngularJS drop down (ng- options) not binding - string to object (initial selection)

前端 未结 2 479
情深已故
情深已故 2021-02-09 19:33

I am having a problem binding data retrieved from the server to a drop down list. The main issue I think is the fact that the comparison is done on differing object types.

2条回答
  •  感情败类
    2021-02-09 20:12

    It is not exactly clear what the problem is, but you can save yourself some work by binding the

    In the above example, $scope.selectedCurrency will be bound to the whole currency object, but currency.shortDescription will be displayed in the dropdown.


    See, also, this short demo.


    UPDATE:

    In case you don't need to bind to the whole currency object, but just bind updatedObject's baseCurrencyCode property to the abbreviation of the selected (in dropdown) currency, you can do it like this:

    
    
    
    // In the CONTROLLER
    $scope.currencies = [...];
    $scope.updatedObject = {
        ...
        baseCurrencyCode: 
    };
    

    See, also, that short demo.

提交回复
热议问题