AngularJS:将资源从一个项目加载到另一个项目

时间:2017-01-25 10:10:04

标签: angularjs spring-boot angular-ui-router

我有两个Spring Boot项目,Project1和Project2。我在'static'文件夹下的两个项目中都有角度代码。我试图从Project1路由到Project2中的资源,如下所示,

src / main / resources / static / index.html(在Project1中)

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="app.js">
</script>
</head>
<body>
<a ui-sref="spendCar">Click here to go to Spend Cat of Project2</a>
</body>
</html>

src / main / resources / static / app.js(在Project1中)

var proj1 = angular.module('proj1', ['ui.router']);

proj1.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');

$stateProvider
    .state('home', {
        url: '/home',
        templateUrl: 'partial-home.html'
    })
    .state('spendcat', {
        url: '/spendcat',
        templateUrl : 'http://localhost:8090/spendcat' //calling Project2's end point
    });

});

在Project2中,我有一个控制器,如下所示,

@Controller
@RequestMapping("/spendcat")
@CrossOrigin
public class SpendCatController {

@RequestMapping(value = "", method = RequestMethod.GET)
public String getSpendCatPage() {
    return "spendcatpage";    //spendcatpage.html is under 'static' folder.
}
}

src / main / resources / static / spendcatpage.html(在Project2中)

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="sc.js">
</script>
</head>
<body>
<div>Welcome to spend category page</div>

<input type="button" onclick="doClick()" value="Click Here">
</body>
</html>

单击“单击此处”按钮时出现错误。如果javascript函数doClick()直接包含在html文件中,那么它可以工作。请建议我如何在project1中加载project2的所有资源。

0 个答案:

没有答案