How to generates dynamically ng-model=“my_{{$index}}” with ng-repeat in AngularJS?

前端 未结 6 639
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 08:16

I would like to ask you if you can give me a hand on this.

I have created a jsfiddle with my problem here. I need to generate dynamically some inputs with ng-model i

6条回答
  •  一整个雨季
    2020-11-29 08:31

    Beterraba's answer was very helpful for me. However, when I had to migrate the solution to Typescript it wouldn't behave for me. Here is what I did instead. I expanded the individual parameters (fields on the queryList in your example) into full objects that included a "value" field. I then bound to the "value" field and it worked great!

    Originally you had:

    [
      { name: 'Check Users', fields: [ "Name", "Id"] },
        ...
      }
    ]
    

    I changed it to something like this:

    [
      { name: 'Check Users', fields: [
                                        {Text:"Name",Value:""},
                                        {Text:"Id",Value:0}],
                                        ...
                                       ]
      }
    ]
    

    ...and bound to the 'Value' sub-field.

    Here is my Typescript if you care.

    In the html:

    In the sproc-param directive that uses Angular Material. See where I bind the ng-model to param.Value:

    return {
        restrict: 'E',
        template: `
                    
                        
                        
                    `,
        scope: {
                param: "="
            }
    }
    

提交回复
热议问题