I have a simple form like this. I am submitting this form via ajax using angularjs. I want to validate this form before sending ajax request and need to show the error to user. I am a newbie to angular. Please Help me
Here is my code.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-messages.js"></script>
<div ng-app="Myapp">
<div ng-controller="orderFormController">
Item : <input type="text" name="item" ng-model='item' required> <p></p>
Rate: <input type="text" name="rate" ng-model='rate' required> <p></p>
<button type="button" ng-click='saveorder()' >SAVE ORDER</button>
</div>
<script>
var Myapp = angular.module('Myapp', ["ngRoute"]);
Myapp.controller('orderFormController', ['$scope', '$http', function ($scope, $http) {
$scope.saveorder = function () {
// Validate form here and set the error in form
$http.post("order/save/", data).success(function (res, status, headers, config) {
$scope.message = res;
}).error(function (data, status) {
$scope.message = res;
});
}
}]);
</script>