How to push object into an array using AngularJS

后端 未结 6 2017
别跟我提以往
别跟我提以往 2020-12-29 19:18

I am trying to do use the angular push function but it is not working.

I want to add strings (or objects) into an array.

I searched for basic examples here

6条回答
  •  遥遥无期
    2020-12-29 19:56

    Push only work for array .

    Make your arrayText object to Array Object.

    Try Like this

    JS

    this.arrayText = [{
      text1: 'Hello',
      text2: 'world',
    }];
    
    this.addText = function(text) {
      this.arrayText.push(text);
    }
    this.form = {
      text1: '',
      text2: ''
    };
    

    HTML

提交回复
热议问题