javascript - Spring web MVC with Angular JS - Routing -


i new angular js , wondering how routing in angular js couples spring web mvc. spring controllers work on requests , hence, if routing login page home page, when -

$routeprovider.when(        '/', {            templateurl : 'home/home.html',            controller : 'homectrl'        })        .when(        '/login', {            templateurl : '/login/login.html',            controller : 'loginctrl'        })        .when(        '/register', {             templateurl : '/login/signup.html',            controller : 'registerctrl'        }); 

then spring controller matching request url, , render view according. point is, entire view should rendered right? entire page reloaded, won't it? takes away entire point of using routing in angular. thinking wrong way? please correct me if thinking wrong.

there 2 main option in hands:

  1. build single page angularjs application

in scenario build fledged angularjs application routing 1 page 1 handled angularjs $routeprovider configuring.

views not defined server side. serve html files static content. assuming put html , js under /app write in xml configuration:

<mvc:resources location="/app/**" mapping="/app/**" /> 

or in javaconfig

@configuration public class myconfig extends webmvcconfigureradapter {   @override public void addresourcehandlers(resourcehandlerregistry registry) {     registry.addresourcehandler("/app/**").addresourcelocations("/app/"); } 

once load home.html page, angularjs application bootstrapped , moment onwards hit server load assets or perform requests against restful api.

that said configure spring mvc in way serves html, js, etc static resources. that's all.

  1. build multi-page application

it possible jump page , have rendered through spring mvc , templating engine of choice server side. feeling experimenting angularjs right now, suggest use first approach now. second approach used large application or satisfy specific scenarios.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -