[英]How can i get data at the angular controller using factory from web api without using port number?
This is my module,这是我的模块,
var app= angular.module('myApp', []);
I have this code at the angular end,我在角端有这个代码,
app.factory("CustomerRegistrationInformation", ["$resource", function ($resource) {
var resource = $resource("http://localhost:8996/api/customerregistration");
return resource;
}]);
But I want a process which is look like below,但我想要一个如下所示的过程,
app.factory("CustomerRegistrationInformation", ["$resource", function ($resource) {
var resource = $resource("~/api/customerregistration");
return resource;
}]);
All requests made from a browser support relative links, so simply starting with a root relative path will work just fine.从浏览器发出的所有请求都支持相对链接,因此只需从根相对路径开始就可以正常工作。
$resource("/api/customerregistration");
Using this as a relative path will ensure that all requests are relative to the root of the website being served up.使用它作为相对路径将确保所有请求都相对于正在提供服务的网站的根目录。
In your case it means http://localhost:8996
when running locally, but could easily be http://www.my-awesome-domain.com
when deployed to production.在您的情况下,它在本地运行时意味着
http://localhost:8996
,但在部署到生产时很容易成为http://www.my-awesome-domain.com
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.