Created
February 27, 2014 22:01
-
-
Save amineeg/9260523 to your computer and use it in GitHub Desktop.
Get started angularJs, send data from angularJs to Php, decode json data in php, best practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// Declare app level module which depends on filters, and services | |
var app= angular.module('myApp', ['ngRoute']); | |
app.config(['$routeProvider', function($routeProvider) { | |
$routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'loginCtrl'}); | |
$routeProvider.otherwise({redirectTo: '/login'}); | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en" ng-app="myApp"> | |
<head> | |
<meta charset="utf-8"> | |
<title>My AngularJS App</title> | |
<link rel="stylesheet" href="css/app.css"/> | |
</head> | |
<body> | |
<div ng-view></div> | |
<!-- In production use: | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
--> | |
<script src="lib/angular/angular.js"></script> | |
<script src="lib/angular/angular-route.js"></script> | |
<script src="js/app.js"></script> | |
<script src="js/directives/loginDrc.js"></script> | |
<script src="js/controllers/loginCtrl.js"></script> | |
<script src="js/services/loginService.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
app.controller('loginCtrl', ['$scope','loginService', function ($scope,loginService) { | |
$scope.msgtxt=''; | |
$scope.login=function(data){ | |
loginService.login(data,$scope); //call login service | |
}; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
app.directive('loginDirective',function(){ | |
return{ | |
templateUrl:'partials/tpl/login.tpl.html' | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
app.factory('loginService',function($http){ | |
return{ | |
login:function(data,scope){ | |
var $promise=$http.post('data/user.php',data); //send data to user.php | |
$promise.then(function(msg){ | |
if(msg.data=='succes') scope.msgtxt='Correct information'; | |
else scope.msgtxt='incorrect information'; | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user=json_decode(file_get_contents('php://input')); //get user from | |
if($user->mail=='[email protected]' && $user->pass=='1234') | |
print 'succes'; | |
else | |
print 'error'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment