Skip to content

Instantly share code, notes, and snippets.

@KiT106
Created October 22, 2016 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KiT106/69dbbdc80ec651942b89629c00f37207 to your computer and use it in GitHub Desktop.
Save KiT106/69dbbdc80ec651942b89629c00f37207 to your computer and use it in GitHub Desktop.
AngularJS $routeProvider.resolve
var app = angular.module("app", ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: "app.html",
controller: "ViewCtrl",
resolve: {
first: function () {
return "Hello world";
},
second: function ($q, $timeout) {
var defer = $q.defer();
$timeout(function () {
defer.reject("Your network is down");
}, 500);
return defer.promise;
}
}
})
});
app.run(function ($rootScope) {
$rootScope.$on("$routeChangeError", function (event, current, previous, rejection) {
console.log(event);
})
});
app.controller("ViewCtrl", function ($scope, first, second) {
console.log(first, second);
$scope.model = {
message: "I'm a great app!"
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment