Created
October 16, 2017 13:24
-
-
Save gmittica/ac0119e88a80f1dfc56e50b5230f5b00 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"> | |
<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 name="main"></ui-view> | |
<div class="well"> | |
<ui-view name="other"></ui-view> | |
</div> | |
</div> | |
<script id="jsbin-javascript"> | |
angular.module("myApp", ['users', 'ui.router', 'cfp.loadingBar']) | |
.config(['$urlRouterProvider', function($urlRouterProvider) { | |
$urlRouterProvider.otherwise('/users'); | |
}]) | |
.run(['$transitions', 'cfpLoadingBar', '$rootScope', function($transitions, cfpLoadingBar, $rootScope) { | |
$transitions.onSuccess({}, function(transition) { | |
console.log(transition.to().data); | |
cfpLoadingBar.complete(); | |
}); | |
$transitions.onStart({}, function(transition) { | |
cfpLoadingBar.start(); | |
}); | |
}]) | |
; | |
angular.module("users", ['ui.router']) | |
.config(['$stateProvider', function($stateProvider) { | |
var s1 = { | |
name: 'users', | |
url: '/users', | |
views: { | |
main: { | |
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' | |
} | |
}, | |
data: { | |
title: 'this is a title', | |
key: 'value' | |
} | |
}; | |
var s2 = { | |
name: 'users-posts', | |
url: '/users/:id/posts?page', | |
views: { | |
other: { | |
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"> | |
</head> | |
<body ng-app="myApp"> | |
<div class="container" > | |
<ui-view name="main"></ui-view> | |
<div class="well"> | |
<ui-view name="other"></ui-view> | |
</div> | |
</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', '$rootScope', function($transitions, cfpLoadingBar, $rootScope) { | |
$transitions.onSuccess({}, function(transition) { | |
console.log(transition.to().data); | |
cfpLoadingBar.complete(); | |
}); | |
$transitions.onStart({}, function(transition) { | |
cfpLoadingBar.start(); | |
}); | |
}]) | |
; | |
angular.module("users", ['ui.router']) | |
.config(['$stateProvider', function($stateProvider) { | |
var s1 = { | |
name: 'users', | |
url: '/users', | |
views: { | |
main: { | |
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' | |
} | |
}, | |
data: { | |
title: 'this is a title', | |
key: 'value' | |
} | |
}; | |
var s2 = { | |
name: 'users-posts', | |
url: '/users/:id/posts?page', | |
views: { | |
other: { | |
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', '$rootScope', function($transitions, cfpLoadingBar, $rootScope) { | |
$transitions.onSuccess({}, function(transition) { | |
console.log(transition.to().data); | |
cfpLoadingBar.complete(); | |
}); | |
$transitions.onStart({}, function(transition) { | |
cfpLoadingBar.start(); | |
}); | |
}]) | |
; | |
angular.module("users", ['ui.router']) | |
.config(['$stateProvider', function($stateProvider) { | |
var s1 = { | |
name: 'users', | |
url: '/users', | |
views: { | |
main: { | |
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' | |
} | |
}, | |
data: { | |
title: 'this is a title', | |
key: 'value' | |
} | |
}; | |
var s2 = { | |
name: 'users-posts', | |
url: '/users/:id/posts?page', | |
views: { | |
other: { | |
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