Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Created February 7, 2018 03:25
Show Gist options
  • Save minhphong306/51f6a838713ae9f44e3dec5da2a0b769 to your computer and use it in GitHub Desktop.
Save minhphong306/51f6a838713ae9f44e3dec5da2a0b769 to your computer and use it in GitHub Desktop.
AngularJS useful snippet
// 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