我怎样才能angularjs动态分配上下文路径 [英] How can i assign context path dynamically in angularjs

查看:763
本文介绍了我怎样才能angularjs动态分配上下文路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在angularjs.For例子而不是给URL动态分配上下文路径:OP /服务/ .....在下面的codeI要分配动态就像我们在JSP做路径网址:'request.getContextPath()/服务/ ... ...既然我不能在其中的功能,我应该使用instead.I不想要硬code,因为我的项目的要求是angularjs使用request.getContextPath()在这样的方式的上下文路径可能为不同的用户而异。

I want to assign context path dynamically in angularjs.For example instead of giving url:'op/services/.....' in the below code i want to assign the path dynamically like we do in jsp "url:'request.getContextPath()/services/...'".Since i cant use request.getContextPath() in angularjs which function i should use instead.I dont want to hardcode it because my project requirement is in such a way that the context path might vary for different users..

$http({
            'url' : '/op/services/saveTemplate',
            'method' : 'GET',
            'headers': {'Content-Type' : 'application/json'},
            'params' : \\something
            }).success(function(data){
                    //some function
             });

在JSP中我们使用request.getContextPath(),但我不知道它的功能,我应该angularjs.I使用搜索的网,但无法找到任何东西...

In jsp we use request.getContextPath() but i am not sure which function i should use in angularjs.I searched the net but couldnt find anything...

推荐答案

做你想要什么,最好的办法是要么获取你需要的AJAX API调用的值,或引导URL在脚本标记和使用全局变量refererence的网址

The best way to do what you want is to either fetch the value you need with an ajax api call,or bootstrap the url in a script tag and use a global variable to refererence the url

<script>
window.myUrl ="<%=somejsp%>";
</script>

在你的页面加载任何其他脚本之前。

before loading any other script in your page.

这篇关于我怎样才能angularjs动态分配上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆