Fórum Problema com Integração RestFull do Spring MVC com AngularJS [ngRoute] #525192
08/07/2015
0
Boa tarde!
Estou com dificuldades ao integrar RestFull do Spring MVC com o ngRoute do AngularJS. Segue abaixo a forma de utilização:
Controller Java que retorna a página:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class InicialController {
@RequestMapping("/inicial")
@ResponseBody
public ModelAndView inicial (){
return new ModelAndView("inicial/inicial");
}
}
OBS: Quando eu acesso (http://localhost:8080/oilproject/inicial) a página é carrega normalmente, então estou certificado que o método a cima esta funcionando...
Bom, então vamos com a configuração do Angular.
var app = angular.module('app', ['ngRoute']);
app.controller('IndexController', function($scope, $route, $routeParams, $location){
console.log("Entrou no Index Controller");
$scope.$route = $route;
$scope.$location = $location;
$scope.$routeParams = $routeParams;
});
app.config(function($routeProvider, $locationProvider){
$routeProvider
.when('/inicial', {
templateUrl : 'inicial/inicial.html',
controller : 'InicialController'
});
$locationProvider.html5Mode({
enabled : true,
requireBase : false
});
});
Página index.html que faz a chamada da página inicial.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body ng-app="app" ng-controller="IndexController">
<a href="inicial"> Clique Aqui para ir Até a Página Inicial</a>
<div ng-view>
</div>
<script type="text/javascript" src="resources/js/angular.min.js"></script>
<script type="text/javascript" src="resources/js/angular-route.min.js"></script>
<script type="text/javascript" src="resources/js/appModule.js"></script>
<script type="text/javascript" src="resources/js/IndexController.js"></script>
</body>
</html>
Alguma sugestão da solução do problema?
Estou com dificuldades ao integrar RestFull do Spring MVC com o ngRoute do AngularJS. Segue abaixo a forma de utilização:
Controller Java que retorna a página:
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class InicialController {
@RequestMapping("/inicial")
@ResponseBody
public ModelAndView inicial (){
return new ModelAndView("inicial/inicial");
}
}
OBS: Quando eu acesso (http://localhost:8080/oilproject/inicial) a página é carrega normalmente, então estou certificado que o método a cima esta funcionando...
Bom, então vamos com a configuração do Angular.
var app = angular.module('app', ['ngRoute']);
app.controller('IndexController', function($scope, $route, $routeParams, $location){
console.log("Entrou no Index Controller");
$scope.$route = $route;
$scope.$location = $location;
$scope.$routeParams = $routeParams;
});
app.config(function($routeProvider, $locationProvider){
$routeProvider
.when('/inicial', {
templateUrl : 'inicial/inicial.html',
controller : 'InicialController'
});
$locationProvider.html5Mode({
enabled : true,
requireBase : false
});
});
Página index.html que faz a chamada da página inicial.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body ng-app="app" ng-controller="IndexController">
<a href="inicial"> Clique Aqui para ir Até a Página Inicial</a>
<div ng-view>
</div>
<script type="text/javascript" src="resources/js/angular.min.js"></script>
<script type="text/javascript" src="resources/js/angular-route.min.js"></script>
<script type="text/javascript" src="resources/js/appModule.js"></script>
<script type="text/javascript" src="resources/js/IndexController.js"></script>
</body>
</html>
Alguma sugestão da solução do problema?
Fundação Funoesc
Curtir tópico
+ 2
Responder
Clique aqui para fazer login e interagir na Comunidade :)