I use Spring MVC and AngularJS for my project. Can AngularJs $routing and ngView be used instead of or together with the Apache Tiles framework? As far as I can see using $routing and ngView we create templates and reuse them in a singlePage application.
问题:
回答1:
Yes, AngularJs' routing can be use instead of tiles. Also you can use together, but after it may broke singlepage app idea.
In tiles you probably use jsp files. So jsp files compiling in server-side , and serving as html file in client side via browser.
In angular also you can create base layout. And like tiles' layout extend
ability , with ng-include
you can include your other views your ng-view
htmls. And when route another page ng-view will refresh included area(Also there are some third party plugins/frameworks on AngularJs about it.Take a look ui-router. It provides nice nested views.).
In Angular way commonly
no need to get html from serverside(this situation may change depending on the other situations. To make singlepage no need.). So you will need to convert your controllers which returns ModelAndView
object to Map(as an example) to return json
. At this time routing will be achieved by angularJs' routes. After these refactorings , you will have a singlepage application. Or you can make hybrid-singlepage
(some pages have too many event so you van start with that pages to make single page to reduce workload) So It will reveal workload depends on your application's size.