Skip to content

Instantly share code, notes, and snippets.

@lvidal1
Created January 13, 2017 18:18
Show Gist options
  • Save lvidal1/8b852415f838a3e114fa62481415443f to your computer and use it in GitHub Desktop.
Save lvidal1/8b852415f838a3e114fa62481415443f to your computer and use it in GitHub Desktop.
Angular - Check if template exist on $routeProvider
$routeProvider.when("/resource/:slug", {
controller: "ResourceController",
resolve: {
check: ["$route", "$http", "$location", function($route, $http, $location){
return $http.get("/views/" + $route.current.params.slug + ".html").success(function(res){
return true;
}).error(function(res){
return $location.path("/");
});
}]
},
template: function($routeParams){
return '<div id="project" ng-include="\'/views/' + $routeParams.slug + '.html\'"></div>';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment