Я ищу, чтобы сделать форму на AngularJS, чтобы отредактировать строку базы данных, доступную через REST API. У меня нет проблем с доступом к данным, у меня действительно есть проблема с настройкой формы для редактирования. Как я смогу отобразить данные, и если пользователь нажмет кнопку отправки, сможет обновить данные. Ниже мой угловой код.AngularJS Редактировать данные/форму
countryApp.controller('EditLocation', function($scope, $http, $routeParams, $location) {
//get the item information
var id = $routeParams.locid;
$scope.activePath = null;
$http.get('http://localhost/slimtest2/location/'+id).success(function(data) {
$scope.location = data;
});
$scope.editrel = function() {
var editData = {
location_title : $scope.l.location_title,
location_latitude : $scope.l.location_latitude,
location_longitude : $scope.l.location_longitude
}
//convert data to JSON string
var loce = JSON.stringify(editData);
$http.put('http://localhost/slimtest2/location/edit', loce);
}
$scope.reset = function() {
$scope.location = data;
}
});
HTML - Редактировать форму
<div ng-controller="EditLocation">
<form name="editform" ng-submit="editrel()">
<div ng-repeat="l in location.location">
<label for="location_title">Location Title</label>
<input type="text" ng-model="l.location_title">
<br/>
<label for="location_latitude">Location Latitude</label>
<input type="text" ng-model="l.location_latitude">
<br/>
<label for="location_longitude">Location Longitude</label>
<input type="text" ng-model="l.location_longitude">
<br/>
<input type="submit" value="Submit">
<input type="button" ng-click="reset()" value="Reset"></input>
</div>
</form>
</div>
Можете ли вы поделиться HTML код формы, чтобы убедиться, что ng-модель верна? – Tomislav
@Tomislav Я просто добавил код формы HTML. –
Вы можете проверить ответ @Exo, просто вызовите $ http.get againe после $ http.put, это была работа. Ваша модель обновится. – Tomislav