AngularJS Essentials
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 5<br />
Consider the following code snippet in the services.js file:<br />
parking.factory("loginService", function ($http) {<br />
var _login = function($scope) {<br />
var user = {<br />
username: $scope.username,<br />
password: $scope.password<br />
};<br />
return $http.post('/login', user);<br />
};<br />
return {<br />
login: _login<br />
};<br />
});<br />
Use a '.' inside the ngModel directive<br />
The framework has the ability to create an object automatically when we introduce<br />
a period in the middle of the ngModel directive. Without that, we ourselves would<br />
need to create the object every time by writing much more code.<br />
In the following code snippet of the login.html file, we will create an object called<br />
user and also define two properties, username and password:<br />
<br />
<br />
<br />
Login<br />
<br />
Consider the following code snippet of the controllers.js file:<br />
parking.controller("loginCtrl", function ($scope, loginService) {<br />
$scope.login = function (user) {<br />
loginService.login(user);<br />
}<br />
});<br />
[ 109 ]<br />
www.it-ebooks.info