Reputation: 121
I am using spring and angular js in my project. In spring I set the view resolver as follows,
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
return viewResolver;
}
In angularjs ,I'm trying to route views/subview/test.html. Code as follows,
$stateProvider
.state("test", {url: "/test", templateUrl: "subview/test.html"});
});
Here the subview is the child folder of view folder.Since I set the view resolver to view folder only it not supports the view/subview/test.html.
Is it possible to setPrefix to all subfolders? If not, suggest other ways to handle this problem.
Upvotes: 2
Views: 199
Reputation: 824
no you will need to set the full path each time - the path is relative to the top level html page the app is running in - you could of course use variables to manage this e.g.
var baseTemplatePath = "/WEB-INF/views/";
$stateProvider
.state("test", {url: "/test", templateUrl: baseTemplatePath + "subview/test.html"});
});
you could also put the variable in a higher level service for access everywhere.
angular.app("yourApp")
.service("pathService", function() {
return {
baseTemplatePath: "/WEB-INF/views/"
};
});
and then use (making sure you have injected the pathService):
$stateProvider
.state("test", {url: "/test", templateUrl: pathService.baseTemplatePath + "subview/test.html"});
});
Upvotes: 2