Data Binding to a specific item of an array in Angular

前端 未结 3 1979
野的像风
野的像风 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

    You can use an array of objects, just not an array of strings.

    HTML:

    JS:

    $scope.data = {
        name: 'F1',
        fields: [
            { val: "v1" },
            { val: "v2" }
        ]
    };
    

    I've updated @Flek's fiddle here: http://jsfiddle.net/RZFm6/6/

    Edit: Sorry just read your question properly, you can still use an array with:

    
    
    

    though maybe stop and think. Is there going to be variable number of fields ? or are you making a predetermined number of fields ? Use an array in the former and an object for the latter.

提交回复
热议问题