Data Binding to a specific item of an array in Angular

前端 未结 3 1988
野的像风
野的像风 2021-02-19 11:41

Given a data structure that contains an array of JavaScript objects, how can I bind a certain entry from that array to an input field using Angular?

The data structure l

3条回答
  •  一整个雨季
    2021-02-19 12:40

    One way to do it is to simply add the necessary references to the scope, like this:

    $scope.fieldF1 = fieldValue('F1');
    $scope.fieldF2 = fieldValue('F2');
    

    And then use those references:

    
    
    

    Fiddle: http://jsfiddle.net/cbnAU/5/

    Note: I'm assuming that $scope.data is static, but if it happens to be dynamic you can always watch for changes on it and recalculate the references...

提交回复
热议问题