Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //service.js
- authApp.factory("loginFactory", function ($http) {
- return{
- login: function(username, password) {
- var data = "username="+username+"&password="+password+"&submit=Login";
- return $http({
- method: 'POST',
- url: 'http://localhost:8080/login',
- data: data,
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- }
- });
- }
- }
- });
- //controller
- authApp.controller('LoginCtrl', ['$scope', '$location', 'loginFactory', function($scope, $location, loginFactory){
- $scope.authenticate = function() {
- loginFactory.login($scope.username, $scope.password)
- .then(function(response) {
- console.log(response.statusText);
- }, function errorCallBack(response) {
- console.log(response.statusText);
- });
- }
- }]);
- <div ng-controller="LoginCtrl">
- <h2>Login</h2>
- <form name="form" ng-submit="authenticate()">
- <div>
- <label for="username">Username</label>
- <input type="text" name="username" id="username" ng-model="username"/>
- <label for="password">Password</label>
- <input type="password" name="password" id="password" ng-model="password"/>
- <button type="submit">Login</button>
- </form>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement