我有一篇文章,当您点击Add
按钮时出现modal
并有3个方框,您可以填写详细信息,保存后会在主页上显示{{1}的列表你新写的项目。
当您点击title
时,它会打开标题为title
的另一个modal
,并且输入字段的2/3似乎正确填充,当您更改值并点击时Edit
它不会更新。
我希望有人可以帮我改变阵列中项目的值来改变我的AngularJS。
提前致谢。
角
Save Changes
答案 0 :(得分:2)
$scope.editlocation = function (locations) {
var locationToEdit = locations;
console.log(locationToEdit);
var modalInstance = $modal.open({
templateUrl: 'edit.html',
controller: ModalInstanceCtrl2,
resolve: {
locations: function () {
return locationToEdit;//Use locationToEdit instead.
}
},
scope: $scope.$new()
});
modalInstance.result.then(function (selectedItem) {
//Update locationToEdit when user saves changes.
locationToEdit.title = selectedItem.title; //Fix typo with titley
locationToEdit.gps = selectedItem.gps;
locationToEdit.desc = selectedItem.desc;
}, function () {
console.log('Modal dismissed at: ' + new Date());
});
ModalInstanceCtrl2 = function ($scope, $modalInstance, locations) {
$scope.input = angular.copy(locations);//create a copy of the editing location so that when the user cancels on the dialog, the object is not updated.
console.log(locations);
$scope.ok = function () {
$modalInstance.close($scope.input);//pass the edited location as a result.
$scope.gps = "";
$scope.title = "";
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};