javascript 在 Restangular 中使用完整 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18001732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using a full URL with Restangular
提问by cazzaran
I like all of the functions of Restangular for AngularJS, except that I can't find (and it may not support) a way of just passing a full URL to it. I realize the benefit of the .one('something','someparam') but my issue is that I'm passed various URL strings, and I really don't want to have to split() them just to use Restangular.
我喜欢 AngularJS 的 Restangular 的所有功能,除了我找不到(并且它可能不支持)只向它传递完整 URL 的方法。我意识到 .one('something','someparam') 的好处,但我的问题是我传递了各种 URL 字符串,我真的不想为了使用 Restangular 就必须对它们进行 split()。
Also, I know about the baseURL function; but these URLs I'm being passed don't necessarily derive from the same base path.
另外,我知道 baseURL 函数;但是我被传递的这些 URL 不一定来自相同的基本路径。
For example, I might have:
例如,我可能有:
/us/en/product/17726
/us/es/products
/us/es/product/991A0
/ca/en/accounts
All I'm given are the Strings...
我得到的只是字符串......
回答by mgonto
I'm the creator of Restangular.
我是 Restangular 的创建者。
You have 2 options to do that.
你有 2 个选择来做到这一点。
1) Creating scoped Restangulars with different BaseURLs in each case: https://github.com/mgonto/restangular#how-to-create-a-restangular-service-with-a-different-configuration-from-the-global-one
1)在每种情况下创建具有不同 BaseURL 的作用域 Restangulars:https: //github.com/mgonto/restangular#how-to-create-a-restangular-service-with-a-different-configuration-from-the-global-一
2) You can use it like Restangular.all('us/en/').one('products', 1726)
or Restangular.one('us/en/product', 1234)
2)你可以像Restangular.all('us/en/').one('products', 1726)
或Restangular.one('us/en/product', 1234)
Hope it works for you :)
希望对你有帮助 :)
回答by slamborne
I needed to simply GET
an absolute url and came across this question.
我只需要GET
一个绝对网址并遇到了这个问题。
Here's how:
就是这样:
Restangular.oneUrl('routeName', 'http://absolute.url').get();
Restangular.oneUrl('routeName', 'http://absolute.url').get();