Using a Relative Path for a Service Call in AngularJS

后端 未结 9 2069
别跟我提以往
别跟我提以往 2020-11-28 03:51

I have the following code, which was working fine until I deployed to a test server:

$scope.getUserList = function (userName) {
    $http({
        method: \         


        
9条回答
  •  离开以前
    2020-11-28 04:06

    In the ng-init function pass a parameter that contains the value the virtual directory (int ASP.NET stored in Request.ApplicationPath).

    Inside the angular controller, use this value as prefix of URL in every http call. You can use this function to combine the paths

    function combinePath(path1, path2) {
        if (path1 == null) {
            return path2;
        }
        var last = path1.slice(-1);
        var first = path2.charAt(0);
    
        if (last == '/' && first == '/') {
            path1 = path1.substring(0, path1.length - 1);
        }
        return path1 + path2;
    }
    

提交回复
热议问题