Created
October 22, 2016 10:31
-
-
Save KiT106/69dbbdc80ec651942b89629c00f37207 to your computer and use it in GitHub Desktop.
AngularJS $routeProvider.resolve
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
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