Created
October 16, 2017 13:03
-
-
Save gmittica/28f2302a9ba06ec3438e1097c9e9ac44 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/rejixi
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> | |
<head> | |
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"></script> | |
<script src="https://code.jquery.com/jquery.min.js"></script> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> | |
<script src="http://unpkg.com/@uirouter/angularjs@1.0.7/release/angular-ui-router.min.js"></script> | |
<link rel='stylesheet' href='http://cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.9.0/loading-bar.min.css' type='text/css' media='all' /> | |
<script type='text/javascript' src='http://cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.9.0/loading-bar.min.js'></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
#loading-bar-spinner { | |
top:50%; | |
background: rgba(0,0,0,0.3); | |
border-radius: 10px; | |
padding:10px; | |
left:45%; | |
} | |
h1 { | |
margin-top:10px; | |
} | |
</style> | |
</head> | |
<body ng-app="myApp"> | |
<div class="container" > | |
<ui-view></ui-view> | |
</div> | |
<script id="jsbin-javascript"> | |
angular.module("myApp", ['users', 'ui.router', 'cfp.loadingBar']) | |
.config(['$urlRouterProvider', function($urlRouterProvider) { | |
$urlRouterProvider.otherwise('/users'); | |
}]) | |
.run(['$transitions', 'cfpLoadingBar', function($transitions, cfpLoadingBar) { | |
$transitions.onSuccess({}, function(transition) { | |
//console.log("FROM: " + transition.from().name + " TO: " + transition.to().name); | |
cfpLoadingBar.complete(); | |
}); | |
$transitions.onStart({}, function(transition) { | |
//console.log("FROM: " + transition.from().name + " TO: " + transition.to().name); | |
cfpLoadingBar.start(); | |
}); | |
}]) | |
; | |
angular.module("users", ['ui.router']) | |
.config(['$stateProvider', function($stateProvider) { | |
var s1 = { | |
name: 'users', | |
url: '/users', | |
template: '<h1>Users <small></h1>' + | |
'<p ng-repeat="user in users"><a ui-sref="users-posts({id: user.id, page: 1})">{{ user.username}}</a></p>', | |
controller: 'UsersCtrl' | |
}; | |
var s2 = { | |
name: 'users-posts', | |
url: '/users/:id/posts?page', | |
template: '<p><small><a ui-sref="users">go back</a></small></p>' + | |
'<h1>Posts of user id {{ id }} page {{ page }}</h1>' + | |
'<p ng-repeat="post in posts | limitTo : (page * 5) : (page * 5 ) - 5">{{ post.title }}</p>', | |
controller: 'UsersPostsCtrl' | |
}; | |
$stateProvider.state(s1); | |
$stateProvider.state(s2); | |
}]) | |
.controller("UsersCtrl", ['$scope', '$http', function($scope, $http) { | |
$scope.users = []; | |
$http.get("https://jsonplaceholder.typicode.com/users").then(function(response) { | |
$scope.users = response.data; | |
}) | |
}]) | |
.controller("UsersPostsCtrl", ['$scope', '$http', '$stateParams', function($scope, $http, $stateParams) { | |
$scope.id = $stateParams.id; | |
$scope.page = $stateParams.page; | |
$scope.posts = []; | |
$http.get("https://jsonplaceholder.typicode.com/posts").then(function(response) { | |
$scope.posts = response.data; | |
}) | |
}]) | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"><\/script> | |
<script src="https://code.jquery.com/jquery.min.js"><\/script> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"><\/script> | |
<script src="//unpkg.com/@uirouter/angularjs@1.0.7/release/angular-ui-router.min.js"><\/script> | |
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.9.0/loading-bar.min.css' type='text/css' media='all' /> | |
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/angular-loading-bar/0.9.0/loading-bar.min.js'><\/script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-app="myApp"> | |
<div class="container" > | |
<ui-view></ui-view> | |
</div> | |
</body> | |
</html></script> | |
<script id="jsbin-source-javascript" type="text/javascript">angular.module("myApp", ['users', 'ui.router', 'cfp.loadingBar']) | |
.config(['$urlRouterProvider', function($urlRouterProvider) { | |
$urlRouterProvider.otherwise('/users'); | |
}]) | |
.run(['$transitions', 'cfpLoadingBar', function($transitions, cfpLoadingBar) { | |
$transitions.onSuccess({}, function(transition) { | |
//console.log("FROM: " + transition.from().name + " TO: " + transition.to().name); | |
cfpLoadingBar.complete(); | |
}); | |
$transitions.onStart({}, function(transition) { | |
//console.log("FROM: " + transition.from().name + " TO: " + transition.to().name); | |
cfpLoadingBar.start(); | |
}); | |
}]) | |
; | |
angular.module("users", ['ui.router']) | |
.config(['$stateProvider', function($stateProvider) { | |
var s1 = { | |
name: 'users', | |
url: '/users', | |
template: '<h1>Users <small></h1>' + | |
'<p ng-repeat="user in users"><a ui-sref="users-posts({id: user.id, page: 1})">{{ user.username}}</a></p>', | |
controller: 'UsersCtrl' | |
}; | |
var s2 = { | |
name: 'users-posts', | |
url: '/users/:id/posts?page', | |
template: '<p><small><a ui-sref="users">go back</a></small></p>' + | |
'<h1>Posts of user id {{ id }} page {{ page }}</h1>' + | |
'<p ng-repeat="post in posts | limitTo : (page * 5) : (page * 5 ) - 5">{{ post.title }}</p>', | |
controller: 'UsersPostsCtrl' | |
}; | |
$stateProvider.state(s1); | |
$stateProvider.state(s2); | |
}]) | |
.controller("UsersCtrl", ['$scope', '$http', function($scope, $http) { | |
$scope.users = []; | |
$http.get("https://jsonplaceholder.typicode.com/users").then(function(response) { | |
$scope.users = response.data; | |
}) | |
}]) | |
.controller("UsersPostsCtrl", ['$scope', '$http', '$stateParams', function($scope, $http, $stateParams) { | |
$scope.id = $stateParams.id; | |
$scope.page = $stateParams.page; | |
$scope.posts = []; | |
$http.get("https://jsonplaceholder.typicode.com/posts").then(function(response) { | |
$scope.posts = response.data; | |
}) | |
}]) | |
</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
#loading-bar-spinner { | |
top:50%; | |
background: rgba(0,0,0,0.3); | |
border-radius: 10px; | |
padding:10px; | |
left:45%; | |
} | |
h1 { | |
margin-top:10px; | |
} |
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
angular.module("myApp", ['users', 'ui.router', 'cfp.loadingBar']) | |
.config(['$urlRouterProvider', function($urlRouterProvider) { | |
$urlRouterProvider.otherwise('/users'); | |
}]) | |
.run(['$transitions', 'cfpLoadingBar', function($transitions, cfpLoadingBar) { | |
$transitions.onSuccess({}, function(transition) { | |
//console.log("FROM: " + transition.from().name + " TO: " + transition.to().name); | |
cfpLoadingBar.complete(); | |
}); | |
$transitions.onStart({}, function(transition) { | |
//console.log("FROM: " + transition.from().name + " TO: " + transition.to().name); | |
cfpLoadingBar.start(); | |
}); | |
}]) | |
; | |
angular.module("users", ['ui.router']) | |
.config(['$stateProvider', function($stateProvider) { | |
var s1 = { | |
name: 'users', | |
url: '/users', | |
template: '<h1>Users <small></h1>' + | |
'<p ng-repeat="user in users"><a ui-sref="users-posts({id: user.id, page: 1})">{{ user.username}}</a></p>', | |
controller: 'UsersCtrl' | |
}; | |
var s2 = { | |
name: 'users-posts', | |
url: '/users/:id/posts?page', | |
template: '<p><small><a ui-sref="users">go back</a></small></p>' + | |
'<h1>Posts of user id {{ id }} page {{ page }}</h1>' + | |
'<p ng-repeat="post in posts | limitTo : (page * 5) : (page * 5 ) - 5">{{ post.title }}</p>', | |
controller: 'UsersPostsCtrl' | |
}; | |
$stateProvider.state(s1); | |
$stateProvider.state(s2); | |
}]) | |
.controller("UsersCtrl", ['$scope', '$http', function($scope, $http) { | |
$scope.users = []; | |
$http.get("https://jsonplaceholder.typicode.com/users").then(function(response) { | |
$scope.users = response.data; | |
}) | |
}]) | |
.controller("UsersPostsCtrl", ['$scope', '$http', '$stateParams', function($scope, $http, $stateParams) { | |
$scope.id = $stateParams.id; | |
$scope.page = $stateParams.page; | |
$scope.posts = []; | |
$http.get("https://jsonplaceholder.typicode.com/posts").then(function(response) { | |
$scope.posts = response.data; | |
}) | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment