【发布时间】:2016-09-24 06:52:48
【问题描述】:
AngularJS 中有没有办法编写 API。实际上,我需要根据外部 Web 请求在我的应用程序(AngularJS 和 Java)中加载一个 HTML 页面。
当我从像这样的服务器端 Web API 执行此操作时
@RequestMapping(value="/test")
public ModelAndView apiTest( HttpServletRequest request, HttpServletResponse response) {
System.out.println("Request comming from outside");
HttpSession session = request.getSession(true);
System.out.println("Api session"+session.getId());
ModelAndView newModel = null;
newModel = new ModelAndView("somepage.html");
return loginModel;
}
上面的代码加载页面,但在请求浏览器上,即从哪里调用 API。反过来,我希望页面加载到当前正在运行的应用程序上。
我该怎么做?
【问题讨论】:
-
您的
HTML文件在哪里? -
在我编写 java API 的服务器上
-
一种解决方法是在客户端移动这些 HTML 文件,比如
templates文件夹,您可以将HTML获取为$http.get('templates/somepage.html').then(function(response){//response.data contains your HTML file's content})然后您可以使用 ng-bind- 操作原始 HTML 内容页面内的html。 -
你的意思是:角度可以从API消费html吗?
-
让我更清楚我的问题(忘记问题中提到的角度 API),我有一个使用(角度和 java)的应用程序,并且用户正在登录该应用程序。现在,每当有人点击特定的 API(来自外部的 url)时,我想在用户端加载一个 html 页面,该页面登录到应用程序而不是在点击 api 的一侧
标签: javascript java html angularjs spring-mvc