मैं कोणीय जेएस के लिए नया हूं, मेरे पास एक सरणी है जिसे मैं ng-repeat
निर्देश के माध्यम से लूप कर रहा हूं, और मैंने सरणी में मूल्यों को कॉपी, हटाने और संपादित करने के लिए कोड लिखा है।कोणीय जेएस में ng-repeat मानों को कैसे अपडेट करें?
अगर मैं हटाना या प्रतिलिपि बनाना चाहता हूं तो मैं कर सकता हूं? लेकिन अगर मैं संपादन पर क्लिक करता हूं तो एक पॉपअप बॉक्स वहां दिखाई देगा, मैं उन मानों को संपादित करना चाहता हूं जो अद्यतन मानों को सरणी में अपडेट करना चाहिए।
मैं इसे कैसे कर सकता हूं?
<!doctype html>
<html>
<head>
<title>Angular app</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style type="text/css">
.listv{
margin-bottom: 30px;
}
.editpopup{
width: 250px;
height: 250px;
border: 1px solid black;
display: none;
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
right: 0px;
background-color:gray;
}
.editpopup-true{
display: block;
}
.editpopup-false{
display: none;
}
</style>
</head>
<body ng-app="myApp">
<div ng-controller="myCon">
<div ng-repeat="s in items" class="listv">
<span>{{s.id}}</span>
<span>{{s.pname}}</span>
<button ng-click="removeStudent($index)">remove</button>
<button ng-click="copyrow($index)">copy</button>
<button ng-click="editrow($index)">edit</button>
</div></br>
<div class="editpopup editpopup-{{istrue}} ">
<p>edit id:<input type="text" ng-model="editedid"></p>
<p>edit pname:<input type="text" ng-model="editedname"></p>
<button ng-click="save($index)">save</button>
<button ng-click="closepopup()">cancel</button>
</div>
</div>
var myApp=angular.module('myApp',[]);
myApp.controller('myCon',function($scope){
$scope.items=[{id:1,pname:'box1'},{id:2,pname:'box2'}, {id:3,pname:'box3'}];
$scope.removeStudent=function($index){
$scope.items.splice($index,1);
}
$scope.copyrow=function($index){
$scope.len=$scope.items.length;
$scope.ids=$scope.items[$index].id;
$scope.pnames=$scope.items[$index].pname
$scope.items.push({
id:$scope.len+1,
pname:$scope.pnames
});
}
$scope.editrow=function($index){
$scope.istrue=true;
$scope.editedid=$scope.items[$index].id;
$scope.editedname=$scope.items[$index].pname;
}
$scope.closepopup=function(){
$scope.istrue=false;
}
$scope.save=function($index){
$scope.istrue=false;
$scope.s.name=$scope.editedname;
}
});
यहाँ jsfiddle
यह मेरे लिए अच्छी तरह से काम किया, क्या कोई अन्य संभव तरीका है? या शायद Angular2 में? धन्यवाद – M98