Created
February 7, 2018 03:25
-
-
Save minhphong306/51f6a838713ae9f44e3dec5da2a0b769 to your computer and use it in GitHub Desktop.
AngularJS useful snippet
This file contains hidden or 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
// Create app with ui router | |
var app = angular.module('app', ['ui.router']); | |
// Controller | |
app.controller('indexCtrl', function ($scope, mainService) { | |
}); | |
// Service for PHP server | |
app.factory('mainService', function ($http) { | |
var mainURI = '/service/'; | |
var factory = {}; | |
factory.doAction = function (data, uri) { | |
return $http({ | |
url: mainURI + uri, | |
method: "POST", | |
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, | |
data: jQuery.param(data) | |
}).then(function (response) { | |
return response; | |
}); | |
}; | |
return factory; | |
}); | |
// Router provider | |
app.config(function ($stateProvider, $urlRouterProvider) { | |
$urlRouterProvider.otherwise('/home'); | |
$stateProvider | |
.state('home', { | |
url: '/home', | |
templateUrl: 'include/pages/index.php', | |
controller: indexCtrl | |
}) | |
.state('girl', { | |
url: '/girl', | |
templateUrl: 'include/pages/girl.php', | |
controller: girlCtrl | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment