Detect If Resource Exists Behind Rewrite Rules With Javascript And Angularjs
I am trying to overwrite portions of my single page app using only javascript and AngularJS. Overwrites are based on subdomain. Every subdomain is pointing to the same doc root. co
Solution 1:
I decided to go with a local stradegy for two reasons:
- There is no additional overhead of XML request.
- 404 messages wont polute console logs when resource doesn't exist.
services.js
factory('Views', function($location,$route,$routeParams,objExistsFilter) {
var viewsService = {};
var views = {
subdomain1:{
'home.html':'/views/subdomain1/home.html'
},
subdomain2:{
},
'home.html':'/views/home.html',
};
viewsService.returnView = function() {
var y = $route.current.template;
var x = $location.host().split(".");
return (x.length>2)?(objExistsFilter(views[x[0]][y]))?views[x[0]][y]:views[y]:views[y];
};
viewsService.returnViews = function() {
return views;
};
return viewsService;
}).
controllers.js
controller('AppController', ['$scope','Views', function($scope, Views) {
$scope.$on("$routeChangeSuccess",function($currentRoute, $previousRoute){
$scope.page = Views.returnView();
});
}]).
filters.js
filter('objExists', function () {
returnfunction (property) {
try {
return property;
} catch (err) {
returnnull
}
};
});
Post a Comment for "Detect If Resource Exists Behind Rewrite Rules With Javascript And Angularjs"