lundi 2 mars 2015

What's wrong with this angular.js form?

I'm having trouble with this simple form: My lack of javascript is holding me back!


If anyone can give me some pointers: I have been unable to find documentation (non-php), which I understand, and gives a full overview of connecting the form data to the '$http' service.


(I'm not getting errors however the data is not registering with the server.)


data format:



{"item_name":"Contact Me Form", "item_data":{"Name":"John Smith", "Email":"john@smith.com", "PhoneNumber":"222-333-4444"}}


script:



angular.module('formApp', [])
.controller('FormController', ['$scope', '$http', function($scope, $http) {
$scope.form_data = {};

$scope.update = function(user) {
$scope.form_data = angular.copy(user);
var dataObject = {
item_name : "Contact Me Form"
,item_data : $scope.form_data
};

var responsePromise = $http.post("http://server-url", dataObject, {});
responsePromise.success(function(dataFromServer, status, headers, config)
{
var outputDate=angular.fromJson(dataFromServer);
});
responsePromise.error(function(data, status, headers, config) {
console.log("Error in fetching user store call!");
});
};
}]);


<div ng-app="formApp">
<div ng-controller="FormController">
<form novalidate class="animated" >
<input
type="text"
ng-model="user.Name"
class="form-control"
id="Name"
placeholder="Your Name" required /><br />
<input
type="email"
ng-model="user.Email"
class="form-control "
id="Email"
placeholder="Company Email" required/><br />
<input
type="text" ng-model="user.PhoneNumber"
class="form-control "
id="Number"
placeholder="Phone - (optional)" /><br />
<input
id="submit"
class="btn-default btn-lg " type="submit"
ng-click="update(user)"
value="Save"
/>
</form>
</div>
</div>

Aucun commentaire:

Enregistrer un commentaire