简体   繁体   English

如何在不使用端口号的情况下使用来自 web api 的工厂获取角度控制器的数据?

[英]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.

相关问题 AngularJS-如何在控制器中使用通过Factory GET请求检索的数据? - AngularJS - How can I use the data retrieved using a Factory GET request in my controller? 我是否在控制器中使用了这个Angular工厂错误? - Am I using this Angular factory wrong from controller? 角度-如何从工厂将解析查询中的对象发送到控制器 - angular - how can I get the object from a parse query out of the factory to the controller 如何使用angularjs从Web API控制器返回数据? - How to return data from web api controller using angularjs? Angular可以从Web Api获取数据 - Angular can get data from Web Api 如何在angularjs中将数据从工厂传递到我的控制器? - How can I pass an data from factory to my controller in angularjs? 如何使用angular将图像发布到Web API? - How can i post image to Web API using angular? 如何使用Firebase将用户数据从Factory返回到控制器 - How to return user data from Factory into a controller using Firebase 在路由时在不使用服务或Factory的情况下将JSON数据从控制器传递到另一个控制器 - Pass the JSON Data Between From Controller To another Controller with out using Services or Factory in angular JS while Routing 如何在angularjs中将数据从控制器获取到Factory - How to get data from controller to Factory in angularjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM