angularjs - How to edit item? -
so have simple example how add , remove items problem editing.i have fiddle:https://jsfiddle.net/b24dqk0r/3/ want when user click ok save item in array.any suggestion?
$scope.save = function (firstname) { $scope.persons.splice(1,firstname) }
<!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>
Comments
Post a Comment