How to edit table list object in AngularJS












0















I am beginner in AngularJS and I am trying to edit table list object using below code and my modal form having save and cancel buttons.



As per my requirement when I click on save button then only object need to update and if I click on cancel button it should not update but using my below code even when I not tap on save button its automatically updating.



How can I do my requirement? Can some one help me please.



add_user.html



<div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">New User Registration</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Username" ng-model="newUser.username">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Email" ng-model="newUser.email">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Full Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Full Name" ng-model="newUser.fullName">
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="saveUser();">Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="close()">Close</button>
</div>
</div>


app.js



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.users;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: $scope.users,
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$scope.users = items;
$uibModalInstance.close();
$scope.users.push($scope.newUser);
$scope.info = "New User Added Successfully!";
$scope.newUser = {};
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$scope.users[user.position] = $scope.newUser;
$uibModalInstance.close();
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);









share|improve this question

























  • Can some one suggest me please

    – Krish
    Nov 16 '18 at 9:33
















0















I am beginner in AngularJS and I am trying to edit table list object using below code and my modal form having save and cancel buttons.



As per my requirement when I click on save button then only object need to update and if I click on cancel button it should not update but using my below code even when I not tap on save button its automatically updating.



How can I do my requirement? Can some one help me please.



add_user.html



<div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">New User Registration</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Username" ng-model="newUser.username">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Email" ng-model="newUser.email">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Full Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Full Name" ng-model="newUser.fullName">
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="saveUser();">Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="close()">Close</button>
</div>
</div>


app.js



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.users;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: $scope.users,
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$scope.users = items;
$uibModalInstance.close();
$scope.users.push($scope.newUser);
$scope.info = "New User Added Successfully!";
$scope.newUser = {};
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$scope.users[user.position] = $scope.newUser;
$uibModalInstance.close();
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);









share|improve this question

























  • Can some one suggest me please

    – Krish
    Nov 16 '18 at 9:33














0












0








0








I am beginner in AngularJS and I am trying to edit table list object using below code and my modal form having save and cancel buttons.



As per my requirement when I click on save button then only object need to update and if I click on cancel button it should not update but using my below code even when I not tap on save button its automatically updating.



How can I do my requirement? Can some one help me please.



add_user.html



<div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">New User Registration</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Username" ng-model="newUser.username">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Email" ng-model="newUser.email">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Full Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Full Name" ng-model="newUser.fullName">
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="saveUser();">Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="close()">Close</button>
</div>
</div>


app.js



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.users;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: $scope.users,
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$scope.users = items;
$uibModalInstance.close();
$scope.users.push($scope.newUser);
$scope.info = "New User Added Successfully!";
$scope.newUser = {};
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$scope.users[user.position] = $scope.newUser;
$uibModalInstance.close();
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);









share|improve this question
















I am beginner in AngularJS and I am trying to edit table list object using below code and my modal form having save and cancel buttons.



As per my requirement when I click on save button then only object need to update and if I click on cancel button it should not update but using my below code even when I not tap on save button its automatically updating.



How can I do my requirement? Can some one help me please.



add_user.html



<div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">New User Registration</h4>
</div>
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Username" ng-model="newUser.username">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Email" ng-model="newUser.email">
</div>
</div>

<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Full Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Full Name" ng-model="newUser.fullName">
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="saveUser();">Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="close()">Close</button>
</div>
</div>


app.js



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.users;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: $scope.users,
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$scope.users = items;
$uibModalInstance.close();
$scope.users.push($scope.newUser);
$scope.info = "New User Added Successfully!";
$scope.newUser = {};
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$scope.users[user.position] = $scope.newUser;
$uibModalInstance.close();
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);






angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 10:32









jess

924110




924110










asked Nov 16 '18 at 8:50









KrishKrish

1,16662056




1,16662056













  • Can some one suggest me please

    – Krish
    Nov 16 '18 at 9:33



















  • Can some one suggest me please

    – Krish
    Nov 16 '18 at 9:33

















Can some one suggest me please

– Krish
Nov 16 '18 at 9:33





Can some one suggest me please

– Krish
Nov 16 '18 at 9:33












2 Answers
2






active

oldest

votes


















1














You should add/edit your user inside the controller myController, to do so, the modal needs to return the user:



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return angular.copy($scope.users);
}
}
});
modalInstance.result.then(function (newUser) {
$scope.users.push(newUser);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: angular.copy($scope.users),
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (user) {
$scope.users[index] = user
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


The fact that we use angular.copy($scope.users); allows us to make sure the modal won't update your list of user.



This line: $uibModalInstance.close($scope.newUser) returns the value to the controller.



Your list is then updated in the modalInstance.result.then function.






share|improve this answer


























  • Remaining my code is fine?

    – Krish
    Nov 16 '18 at 10:21











  • No, sorry, I updated my answer since you were saving your user inside the modal. It is bad practice, the modal should return the user and the controller should behave accordingly

    – Groben
    Nov 16 '18 at 10:23











  • very clear thanks a lot

    – Krish
    Nov 16 '18 at 10:39











  • why your returning arrayList: angular.copy($scope.users), instead of arrayList: $scope.users

    – Krish
    Nov 16 '18 at 10:59











  • please clarify my doubt

    – Krish
    Nov 16 '18 at 10:59



















-1














I dont see ng-app being added or the controller being referenced anywhere in the HTML






share|improve this answer
























  • controller being referenced

    – Krish
    Nov 16 '18 at 9:51











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating

    – Krish
    Nov 16 '18 at 9:52











  • controller being referenced Where?

    – krishnanspace
    Nov 16 '18 at 9:54











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating I'm not able to understand you.

    – krishnanspace
    Nov 16 '18 at 9:54













  • when i open modal form with out tap save button its updating table list object ,I want to update when i click save button

    – Krish
    Nov 16 '18 at 10:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334319%2fhow-to-edit-table-list-object-in-angularjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You should add/edit your user inside the controller myController, to do so, the modal needs to return the user:



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return angular.copy($scope.users);
}
}
});
modalInstance.result.then(function (newUser) {
$scope.users.push(newUser);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: angular.copy($scope.users),
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (user) {
$scope.users[index] = user
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


The fact that we use angular.copy($scope.users); allows us to make sure the modal won't update your list of user.



This line: $uibModalInstance.close($scope.newUser) returns the value to the controller.



Your list is then updated in the modalInstance.result.then function.






share|improve this answer


























  • Remaining my code is fine?

    – Krish
    Nov 16 '18 at 10:21











  • No, sorry, I updated my answer since you were saving your user inside the modal. It is bad practice, the modal should return the user and the controller should behave accordingly

    – Groben
    Nov 16 '18 at 10:23











  • very clear thanks a lot

    – Krish
    Nov 16 '18 at 10:39











  • why your returning arrayList: angular.copy($scope.users), instead of arrayList: $scope.users

    – Krish
    Nov 16 '18 at 10:59











  • please clarify my doubt

    – Krish
    Nov 16 '18 at 10:59
















1














You should add/edit your user inside the controller myController, to do so, the modal needs to return the user:



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return angular.copy($scope.users);
}
}
});
modalInstance.result.then(function (newUser) {
$scope.users.push(newUser);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: angular.copy($scope.users),
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (user) {
$scope.users[index] = user
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


The fact that we use angular.copy($scope.users); allows us to make sure the modal won't update your list of user.



This line: $uibModalInstance.close($scope.newUser) returns the value to the controller.



Your list is then updated in the modalInstance.result.then function.






share|improve this answer


























  • Remaining my code is fine?

    – Krish
    Nov 16 '18 at 10:21











  • No, sorry, I updated my answer since you were saving your user inside the modal. It is bad practice, the modal should return the user and the controller should behave accordingly

    – Groben
    Nov 16 '18 at 10:23











  • very clear thanks a lot

    – Krish
    Nov 16 '18 at 10:39











  • why your returning arrayList: angular.copy($scope.users), instead of arrayList: $scope.users

    – Krish
    Nov 16 '18 at 10:59











  • please clarify my doubt

    – Krish
    Nov 16 '18 at 10:59














1












1








1







You should add/edit your user inside the controller myController, to do so, the modal needs to return the user:



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return angular.copy($scope.users);
}
}
});
modalInstance.result.then(function (newUser) {
$scope.users.push(newUser);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: angular.copy($scope.users),
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (user) {
$scope.users[index] = user
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


The fact that we use angular.copy($scope.users); allows us to make sure the modal won't update your list of user.



This line: $uibModalInstance.close($scope.newUser) returns the value to the controller.



Your list is then updated in the modalInstance.result.then function.






share|improve this answer















You should add/edit your user inside the controller myController, to do so, the modal needs to return the user:



var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myController', ['$scope', '$uibModal', '$log',
function ($scope, $uibModal, $log) {
$scope.newUser = {};
$scope.info = "";
$scope.users = [
{ username: "rimon", fullName: "Md. Mamunur Rashid Rimon", email: "rimonmath@gmail.com" },
{ username: "shamim", fullName: "Md. Tamim Hossain", email: "shamim@gmail.com" },
{ username: "tamim", fullName: "Tamim Iqbal", email: "tamim@gmail.com" }
];

$scope.addUser = function () {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return angular.copy($scope.users);
}
}
});
modalInstance.result.then(function (newUser) {
$scope.users.push(newUser);
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
}

$scope.editUser = function (index) {
var modalInstance = $uibModal.open({
templateUrl: 'add_user.html',
controller: 'EditInstanceCtrl',
resolve: {
user: function () {
var obj = {
arrayList: angular.copy($scope.users),
position: index
}
return obj;
}
}
});
modalInstance.result.then(function (user) {
$scope.users[index] = user
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};

$scope.deleteUser = function () {
console.log($scope.users.indexOf($scope.clickedUser));
$scope.users.splice($scope.users.indexOf($scope.clickedUser), 1);
$scope.info = "User Deleted Successfully!";
};

$scope.clearInfo = function () {
$scope.info = "";
};

}]);


angular.module('myApp').controller('ModalInstanceCtrl', ['$scope', '$uibModalInstance', 'items',
function ($scope, $uibModalInstance, items) {
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};

$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


angular.module('myApp').controller('EditInstanceCtrl', ['$scope', '$uibModalInstance', 'user',
function ($scope, $uibModalInstance, user) {
$scope.newUser = user.arrayList[user.position];
$scope.users = user.arrayList;
$scope.saveUser = function () {
$uibModalInstance.close($scope.newUser);
};
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);


The fact that we use angular.copy($scope.users); allows us to make sure the modal won't update your list of user.



This line: $uibModalInstance.close($scope.newUser) returns the value to the controller.



Your list is then updated in the modalInstance.result.then function.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 10:22

























answered Nov 16 '18 at 10:09









GrobenGroben

1,0061823




1,0061823













  • Remaining my code is fine?

    – Krish
    Nov 16 '18 at 10:21











  • No, sorry, I updated my answer since you were saving your user inside the modal. It is bad practice, the modal should return the user and the controller should behave accordingly

    – Groben
    Nov 16 '18 at 10:23











  • very clear thanks a lot

    – Krish
    Nov 16 '18 at 10:39











  • why your returning arrayList: angular.copy($scope.users), instead of arrayList: $scope.users

    – Krish
    Nov 16 '18 at 10:59











  • please clarify my doubt

    – Krish
    Nov 16 '18 at 10:59



















  • Remaining my code is fine?

    – Krish
    Nov 16 '18 at 10:21











  • No, sorry, I updated my answer since you were saving your user inside the modal. It is bad practice, the modal should return the user and the controller should behave accordingly

    – Groben
    Nov 16 '18 at 10:23











  • very clear thanks a lot

    – Krish
    Nov 16 '18 at 10:39











  • why your returning arrayList: angular.copy($scope.users), instead of arrayList: $scope.users

    – Krish
    Nov 16 '18 at 10:59











  • please clarify my doubt

    – Krish
    Nov 16 '18 at 10:59

















Remaining my code is fine?

– Krish
Nov 16 '18 at 10:21





Remaining my code is fine?

– Krish
Nov 16 '18 at 10:21













No, sorry, I updated my answer since you were saving your user inside the modal. It is bad practice, the modal should return the user and the controller should behave accordingly

– Groben
Nov 16 '18 at 10:23





No, sorry, I updated my answer since you were saving your user inside the modal. It is bad practice, the modal should return the user and the controller should behave accordingly

– Groben
Nov 16 '18 at 10:23













very clear thanks a lot

– Krish
Nov 16 '18 at 10:39





very clear thanks a lot

– Krish
Nov 16 '18 at 10:39













why your returning arrayList: angular.copy($scope.users), instead of arrayList: $scope.users

– Krish
Nov 16 '18 at 10:59





why your returning arrayList: angular.copy($scope.users), instead of arrayList: $scope.users

– Krish
Nov 16 '18 at 10:59













please clarify my doubt

– Krish
Nov 16 '18 at 10:59





please clarify my doubt

– Krish
Nov 16 '18 at 10:59













-1














I dont see ng-app being added or the controller being referenced anywhere in the HTML






share|improve this answer
























  • controller being referenced

    – Krish
    Nov 16 '18 at 9:51











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating

    – Krish
    Nov 16 '18 at 9:52











  • controller being referenced Where?

    – krishnanspace
    Nov 16 '18 at 9:54











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating I'm not able to understand you.

    – krishnanspace
    Nov 16 '18 at 9:54













  • when i open modal form with out tap save button its updating table list object ,I want to update when i click save button

    – Krish
    Nov 16 '18 at 10:00
















-1














I dont see ng-app being added or the controller being referenced anywhere in the HTML






share|improve this answer
























  • controller being referenced

    – Krish
    Nov 16 '18 at 9:51











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating

    – Krish
    Nov 16 '18 at 9:52











  • controller being referenced Where?

    – krishnanspace
    Nov 16 '18 at 9:54











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating I'm not able to understand you.

    – krishnanspace
    Nov 16 '18 at 9:54













  • when i open modal form with out tap save button its updating table list object ,I want to update when i click save button

    – Krish
    Nov 16 '18 at 10:00














-1












-1








-1







I dont see ng-app being added or the controller being referenced anywhere in the HTML






share|improve this answer













I dont see ng-app being added or the controller being referenced anywhere in the HTML







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 9:48









krishnanspacekrishnanspace

368




368













  • controller being referenced

    – Krish
    Nov 16 '18 at 9:51











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating

    – Krish
    Nov 16 '18 at 9:52











  • controller being referenced Where?

    – krishnanspace
    Nov 16 '18 at 9:54











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating I'm not able to understand you.

    – krishnanspace
    Nov 16 '18 at 9:54













  • when i open modal form with out tap save button its updating table list object ,I want to update when i click save button

    – Krish
    Nov 16 '18 at 10:00



















  • controller being referenced

    – Krish
    Nov 16 '18 at 9:51











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating

    – Krish
    Nov 16 '18 at 9:52











  • controller being referenced Where?

    – krishnanspace
    Nov 16 '18 at 9:54











  • my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating I'm not able to understand you.

    – krishnanspace
    Nov 16 '18 at 9:54













  • when i open modal form with out tap save button its updating table list object ,I want to update when i click save button

    – Krish
    Nov 16 '18 at 10:00

















controller being referenced

– Krish
Nov 16 '18 at 9:51





controller being referenced

– Krish
Nov 16 '18 at 9:51













my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating

– Krish
Nov 16 '18 at 9:52





my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating

– Krish
Nov 16 '18 at 9:52













controller being referenced Where?

– krishnanspace
Nov 16 '18 at 9:54





controller being referenced Where?

– krishnanspace
Nov 16 '18 at 9:54













my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating I'm not able to understand you.

– krishnanspace
Nov 16 '18 at 9:54







my requirement when i click on save button then only object need to update and if i click on cancel button it should not update but using my below code even when i not tap on save button its automatically updating I'm not able to understand you.

– krishnanspace
Nov 16 '18 at 9:54















when i open modal form with out tap save button its updating table list object ,I want to update when i click save button

– Krish
Nov 16 '18 at 10:00





when i open modal form with out tap save button its updating table list object ,I want to update when i click save button

– Krish
Nov 16 '18 at 10:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334319%2fhow-to-edit-table-list-object-in-angularjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?