AngularJS写入然后编辑数组
我有一篇文章,当你点击AngularJS写入然后编辑数组,angularjs,angularjs-scope,angularjs-ng-repeat,Angularjs,Angularjs Scope,Angularjs Ng Repeat,我有一篇文章,当你点击添加按钮时,会出现一个模式,并有3个框供你填写详细信息,保存后会在主页上显示一个列表,其中包含你新写的项目的标题 当您单击标题时,它将打开另一个模式,标题为编辑,其中2/3的输入字段似乎填写正确,当您更改值并单击保存更改时,它不会更新 我希望有人能在我的AngularJS中帮助我更改数组中项目的值 提前谢谢 棱角分明 var theApp = angular.module('theApp', []); var app = angular.module('theApp',
添加
按钮时,会出现一个模式
,并有3个框供你填写详细信息,保存后会在主页上显示一个列表,其中包含你新写的项目的标题
当您单击标题
时,它将打开另一个模式
,标题为编辑
,其中2/3的输入字段似乎填写正确,当您更改值并单击保存更改
时,它不会更新
我希望有人能在我的AngularJS中帮助我更改数组中项目的值
提前谢谢
棱角分明
var theApp = angular.module('theApp', []);
var app = angular.module('theApp', ['ui.bootstrap']);
app.controller('MenuSideController', ['$scope','$modal','$log', function($scope, $modal, $log) {
var ModalInstanceCtrl;
$scope.locations = [];
$scope.savenewmarker = function() {
$scope.keys.push({ title: '', gps:'', desc:''});
};
$scope.createmarker = function () {
var modalInstance = $modal.open({
templateUrl: 'modal.html',
controller: ModalInstanceCtrl,
resolve: {},
scope: $scope.$new()
});
modalInstance.result.then(function (selectedItem) {
$scope.locations.push({title: selectedItem.titley, gps:selectedItem.gps, desc:selectedItem.desc});
}, function () {
console.log('Modal dismissed at: ' + new Date());
});
};
$scope.editlocation = function (locations) {
var locationToEdit = locations;
console.log(locationToEdit);
var modalInstance = $modal.open({
templateUrl: 'edit.html',
controller: ModalInstanceCtrl2,
resolve: {
locations: function () {
return $scope.locations;
}
},
scope: $scope.$new()
});
modalInstance.result.then(function (selectedItem) {
console.log('selectedItem: '+selectedItem.titley);
$scope.locations[0].title = selectedItem.titley;
$scope.locations[0].gps = selectedItem.gps;
//$scope.locations.push({title: selectedItem.titley, gps:selectedItem.gps, desc:selectedItem.desc});
}, function () {
console.log('Modal dismissed at: ' + new Date());
});
};
ModalInstanceCtrl = function ($scope, $modalInstance) {
$scope.input = [];
$scope.ok = function () {
$modalInstance.close($scope.input);
$scope.gps = "";
$scope.title = "";
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};
ModalInstanceCtrl2 = function ($scope, $modalInstance, locations) {
$scope.input = [];
console.log(locations);
$scope.ok = function () {
$modalInstance.close($scope.locations);
$scope.gps = "";
$scope.title = "";
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};
$scope.plotmarkers = function() {
console.log($scope);
};
}]);
theApp.factory('CategoryService', ['$http', function($http){
return {
getList: function(){
return $http.get('/directory/assets/inc/category.php');
}
};
}
]);
看
你的物品还没满,我找不到在哪里点击title@IlanFrumer现在代码中的链接已更新-当我更改
title
时,它会工作并更改,但当我更改gps
时,它根本不工作。检查你的plunk@Donald当前位置也许有错,让我来告诉你check@Donald:我更新了plunk。您的原始文件中有一些拼写错误,其中有titley
$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');
};
};