javascript - Edit fields in angularjs -
hi beginner in angularjs , trying implement edit of field , trying save data..
the below html:-
<div class="row" ng-if="showme=='false'"> <div class="myaddress"> <div class="card-addresses"> <div class="card card-address" ng-repeat="address in addresses" ng-click="selectaddress(address)" ng-class="{active : selectedaddress === address}"> <div class="overlay"> <div class="icon icon-approved"></div> </div> <div class="card-header"> <div class="pull-left"><span>{{address.label}}</span></div> <div class="pull-right"><i class="fa fa-pencil" ng-click="editaddress(address)"></i> <div class="editpopup editpopup-{{istrue}}"> <p>edit id: <input type="text" ng-model="address.street"/> </p> <p>edit pname: <input type="text" ng-model="address.station"/> </p> <button ng-click="save()">save</button> <button ng-click="closepopup()">cancel</button> </div> <i class="fa fa-trash" ng-click="deladdress(address)"></i> </div> </div> <div class="card-block"> <p>{{address.building}}</p> <p>{{address.street}}</p> <p>{{address.station}} {{address.city}} - {{address.pincode}}</p> </div> <div class="card-footer"><span>default</span></div> </div> </div> <button class="btn btn-success btn-block" type="button" ng-click="addaddress()">add new address</button> </div>
the below js:-
$scope.editrow=function($index){ $scope.istrue=true; $scope.$index = $index; angular.copy($scope.address[$index], $scope.address); } $scope.closepopup=function(){ $scope.istrue=false; } $scope.save = function() { $scope.istrue=false; angular.copy($scope.addresses, $scope.addresses[0]) address.save($scope.addresses) };
i trying fetch , save data in service address gets getting value database
you need store edit state in each address
so html
<div class="row" ng-if="showme=='false'"> <div class="myaddress"> <div class="card-addresses"> <div class="card card-address" ng-repeat="address in addresses" ng-click="selectaddress(address)" ng-class="{active : selectedaddress === address}"> <div class="overlay"> <div class="icon icon-approved"></div> </div> <div class="card-header"> <div class="pull-left"><span>{{address.label}}</span></div> <div class="pull-right"><i class="fa fa-pencil" ng-click="editaddress(address)"></i> <div class="editpopup editpopup-{{address.istrue}}"> <p>edit id: <input type="text" ng-model="address.street"/> </p> <p>edit pname: <input type="text" ng-model="address.station"/> </p> <button ng-click="save(address)">save</button> <button ng-click="closepopup(address)">cancel</button> </div> <i class="fa fa-trash" ng-click="deladdress(address)"></i> </div> </div> <div class="card-block"> <p>{{address.building}}</p> <p>{{address.street}}</p> <p>{{address.station}} {{address.city}} - {{address.pincode}}</p> </div> <div class="card-footer"><span>default</span></div> </div> </div> <button class="btn btn-success btn-block" type="button" ng-click="addaddress()">add new address</button> </div>
and js
$scope.editrow=function($index){ $scope.istrue=true; $scope.$index = $index; //angular.copy($scope.address[$index], $scope.address); // why need this? } $scope.closepopup=function(address){ address.istrue=false; } $scope.save = function() { address.istrue=false; // angular.copy($scope.addresses, $scope.addresses[0])// why need this? address.save($scope.addresses) };
Comments
Post a Comment