Basic Form with $http Post
by Md Naveed
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<body ng-app="Signup">
<div ng-controller="SignupController">
<form novalidate class="simple-form">
E-mail:
<input type="email" ng-model="dataForServer.email" />
<br /> Name:
<input type="text" ng-model="dataForServer.name" />
<br /> Password:
<input type="password" ng-model="dataForServer.password" />
<br /> Confirm Password:
<input type="password" ng-model="dataForServer.confirmPassword" />
<br /> Privacy:
<input type="checkbox" ng-model="dataForServer.privacyAccepted" />
<br /> Terms Accepted:
<input type="checkbox" ng-model="dataForServer.termsAccepted" />
<br /> Supress Email:
<input type="checkbox" ng-model="dataForServer.suppressEmail" />
<br />
<input type="button" ng-click="reset()" value="Reset" />
<input type="submit" ng-click="update(dataForServer)" value="Save" />
</form>
<pre>user = {{dataForServer | json}}</pre>
</div>
<script>
angular.module('Signup', [])
.controller('SignupController', ['$scope', '$http', function($scope, $http) {
$scope.dataForServer = {
// merchantId: new Date().getTime(),
role: "ROLE_ADMIN"
};
$scope.update = function(dataForServer) {
var oData = angular.copy(dataForServer);
debugger;
$http.post('merchant_api_url/api/user', oData).success(function(data, status) {
// handle success
}).error(function() {
// handle error
})
};
$scope.reset = function() {
$scope.dataForServer = {
...