Angularjs 如何编辑项目?

Angularjs 如何编辑项目?,angularjs,Angularjs,所以我有一个简单的例子,如何添加和删除项目,但问题在于编辑。我有一个小问题:我想当用户单击“确定”时将该项目保存在数组中。有什么建议吗 $scope.Save = function (firstName) { $scope.Persons.splice(1,firstName) } 在此处插入标题 var-app=angular.module('myApp',[]); 应用程序控制器('myCtrl',函数($scope){ $scope.Persons=[]; $scope.firs

所以我有一个简单的例子,如何添加和删除项目,但问题在于编辑。我有一个小问题:我想当用户单击“确定”时将该项目保存在数组中。有什么建议吗

$scope.Save = function (firstName)
{
  $scope.Persons.splice(1,firstName)
} 

在此处插入标题
var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
$scope.Persons=[];
$scope.firstName=“”;
$scope.showEdit=false;
$scope.editValue=“”;
$scope.addItem=函数(项)
{
$scope.Persons.push(项目);
$scope.firstName=“”;
}
$scope.removietem=功能(个人)
{
$scope.Persons.splice($scope.Persons.indexOf(person),1);
}
$scope.editPersons=函数(项){
$scope.showEdit=true;
$scope.editValue=项目;
$scope.helpEdit=项目;
}   
$scope.Save=函数()
{
editVal=$scope.Persons.splice($scope.Persons.indexOf($scope.helpEdit),1);
$scope.Persons.push($scope.editValue);
$scope.editValue=“”;
$scope.showEdit=false;
控制台日志(editVal);
} 
});
名字:

  • {{person}}删除 更新
名字:
拯救 添加
搜寻
在得到答案后,你会像上次一样删除你的问题吗?我不会删除问题..你会帮我解决问题吗?
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="angular/angular.min.js"></script>
    <script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.Persons = [];
        $scope.firstName = "";
        $scope.showEdit = false;
        $scope.editValue="";

       $scope.addItem = function(item)
    {
        $scope.Persons.push(item);
        $scope.firstName ="";
    }
        $scope.removeItem = function(person)
        {
             $scope.Persons.splice( $scope.Persons.indexOf(person), 1 );
        }
        $scope.editPersons = function (item) {  
         $scope.showEdit = true;
         $scope.editValue = item;
         $scope.helpEdit = item;
        }   
        $scope.Save = function ()
        {
         editVal = $scope.Persons.splice( $scope.Persons.indexOf($scope.helpEdit), 1 );
         $scope.Persons.push($scope.editValue);
         $scope.editValue="";
         $scope.showEdit = false;
         console.log(editVal);
        } 

    });

    </script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">

First Name: <input type="text" ng-model="firstName"><br>

<br>
<ul ng-repeat="person in Persons | filter:search">
<li>{{person}}<button type="button" ng-click="removeItem(person)">REMOVE</button>
<button type="button" ng-click="editPersons(person)">UPDATE</button>
</li>

</ul>
<div ng-show="showEdit">
First Name: <input type="text" ng-model="editValue"><br>
    <button type="button" ng-click="Save()">SAVE</button>

</div>
<button type="button" ng-click="addItem(firstName)">ADD</button>
<br/>
    <label>SEARCH</label><input type="search" ng-model="search" />
</div>

</body>
</html>