How to create an Array with AngularJS's ng-model

前端 未结 6 2054
感情败类
感情败类 2020-12-01 02:30

I\'m trying to create an array holding telephones, i have this code




        
6条回答
  •  抹茶落季
    2020-12-01 03:06

    You can do a variety of things. What I would do is this.

    Create an array on scope that will be your data structure for the phone numbers.

    $scope.telephone = '';
    $scope.numbers = [];
    

    Then in your html I would have this

    
    
    

    Then when your user clicks submit, run submitNumber(), which pushes the new telephone number into the numbers array.

    $scope.submitNumber = function(){
      $scope.numbers.push($scope.telephone);
    }
    

提交回复
热议问题