Angularjs 动态地将项添加到ng重复保留重复模型

Angularjs 动态地将项添加到ng重复保留重复模型,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我正在创建一个网页,向用户提供动态添加行项目的选项。我使用了angularjs框架(V1.4.7)。我能够实现动态添加项到ng repeat的效果,但在动态添加项中,模式似乎不是唯一的 下面是显示问题的演示代码: <div> <form novalidate class="form-vertical" ng-show="!loading" name="detailsForm" ng-controller="DetailsCtrl"> <div ng-repea

我正在创建一个网页,向用户提供动态添加行项目的选项。我使用了angularjs框架(V1.4.7)。我能够实现动态添加项到ng repeat的效果,但在动态添加项中,模式似乎不是唯一的

下面是显示问题的演示代码:

<div>
<form novalidate class="form-vertical" ng-show="!loading" name="detailsForm" ng-controller="DetailsCtrl">

  <div ng-repeat="social in socials track by $index">
      <ng-form name="urlForm">
            <input type="email" name="socialUrl" ng-model="social.email">
            <span class="alert error" ng-show="urlForm.socialUrl.$error.email">Email error</span>
      </ng-form>
  </div>  
  <a title="Add" class="btn btn-success" href="javascript:void(null)" ng-click="addSocial()"><i class="fa fa-plus fa-lg"></i> Add</a>
</form>
</div>

var myApp = angular.module('myApp', []);

myApp.controller('DetailsCtrl', ['$scope', function($scope) {
    $scope.loading = false;
    var social = {"email":""};

    $scope.socials = [
            { email: 'test@test.com'},
        { email: 'invalid email'}];


  $scope.addSocial = function(){
    $scope.socials.push(social);
  };

    }]
    );

电子邮件错误
var myApp=angular.module('myApp',[]);
myApp.controller('DetailsCtrl',['$scope',函数($scope){
$scope.loading=false;
var social={“email”:“};
$scope.socials=[
{电子邮件:'test@test.com'},
{电子邮件:'无效电子邮件'}];
$scope.addSocial=function(){
$scope.socials.push(社交);
};
}]
);
我已经创建了显示问题的示例。在小提琴中,请添加一个新项目“12345@email.com". 添加另一项“54321@email.com". 您会注意到,在输入第二个项目时,第一个添加的项目也会发生更改


这是因为您将同一对象添加到数组中,然后您没有将社交活动分配给新对象。这样可以保持它的绑定

:


非常感谢@Voreny。你让我开心:)
$scope.addSocial = function(){
    $scope.socials.push(social);
    social = {"email": ""};
  };