Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用angularjs$resource从web api调用自定义方法_Javascript_C#_.net_Angularjs_Ngresource - Fatal编程技术网

Javascript 使用angularjs$resource从web api调用自定义方法

Javascript 使用angularjs$resource从web api调用自定义方法,javascript,c#,.net,angularjs,ngresource,Javascript,C#,.net,Angularjs,Ngresource,以下是我的webapi操作: [RoutePrefix("api/CustomTemplate")] public class CustomTemplateController : ApiController { [HttpGet] [Route("GetCustomTemplate")] public IHttpActionResult GetCustomTemplate() { //Code } } 以下是我的angularjs文

以下是我的
webapi
操作:

[RoutePrefix("api/CustomTemplate")]
public class CustomTemplateController : ApiController
{
    [HttpGet]
    [Route("GetCustomTemplate")]
    public IHttpActionResult GetCustomTemplate()
    {
         //Code 
    }
}
以下是我的angularjs文件:

服务文件:

'use strict';
app.factory('customService', ['$resource', 'ngAuthSettings', function ($resource, ngAuthSettings) {

var serviceBase = ngAuthSettings.apiServiceBaseUri;

return $resource(serviceBase + 'api/CustomTemplate/', {}, {
    query: { method: 'GET', isArray: true },
    getCustomTemplate: {
        url: 'GetCustomTemplate',
        method: 'GET',
        isArray: false
    }
});
}]);
'use strict';
app.controller('customController', [
    '$scope', 'customService', function ($scope, customService) 
    {
        customService.getCustomTemplate({},function (customTemplate) 
        {
            $scope.customTemplate = customTemplate;
        });        
    }
]);
我的angularjs控制器:

'use strict';
app.factory('customService', ['$resource', 'ngAuthSettings', function ($resource, ngAuthSettings) {

var serviceBase = ngAuthSettings.apiServiceBaseUri;

return $resource(serviceBase + 'api/CustomTemplate/', {}, {
    query: { method: 'GET', isArray: true },
    getCustomTemplate: {
        url: 'GetCustomTemplate',
        method: 'GET',
        isArray: false
    }
});
}]);
'use strict';
app.controller('customController', [
    '$scope', 'customService', function ($scope, customService) 
    {
        customService.getCustomTemplate({},function (customTemplate) 
        {
            $scope.customTemplate = customTemplate;
        });        
    }
]);
我的问题是,我无法从angularjs调用
GetCustomTemplate
。有人能告诉我我做错了什么吗?

你必须拨打完整的URL

'use strict';
app.factory('customService', ['$resource', 'ngAuthSettings', function ($resource, ngAuthSettings) {

var serviceBase = ngAuthSettings.apiServiceBaseUri;

return $resource(serviceBase + 'api/CustomTemplate/', {}, {
    query: { method: 'GET', isArray: true },
    getCustomTemplate: {
        url: serviceBase +'api/CustomTemplate/GetCustomTemplate', //full URL + custom action
        method: 'GET',
        isArray: false
    }
});
}]);
您必须调用完整的URL

'use strict';
app.factory('customService', ['$resource', 'ngAuthSettings', function ($resource, ngAuthSettings) {

var serviceBase = ngAuthSettings.apiServiceBaseUri;

return $resource(serviceBase + 'api/CustomTemplate/', {}, {
    query: { method: 'GET', isArray: true },
    getCustomTemplate: {
        url: serviceBase +'api/CustomTemplate/GetCustomTemplate', //full URL + custom action
        method: 'GET',
        isArray: false
    }
});
}]);
您必须调用完整的URL

'use strict';
app.factory('customService', ['$resource', 'ngAuthSettings', function ($resource, ngAuthSettings) {

var serviceBase = ngAuthSettings.apiServiceBaseUri;

return $resource(serviceBase + 'api/CustomTemplate/', {}, {
    query: { method: 'GET', isArray: true },
    getCustomTemplate: {
        url: serviceBase +'api/CustomTemplate/GetCustomTemplate', //full URL + custom action
        method: 'GET',
        isArray: false
    }
});
}]);
您必须调用完整的URL

'use strict';
app.factory('customService', ['$resource', 'ngAuthSettings', function ($resource, ngAuthSettings) {

var serviceBase = ngAuthSettings.apiServiceBaseUri;

return $resource(serviceBase + 'api/CustomTemplate/', {}, {
    query: { method: 'GET', isArray: true },
    getCustomTemplate: {
        url: serviceBase +'api/CustomTemplate/GetCustomTemplate', //full URL + custom action
        method: 'GET',
        isArray: false
    }
});
}]);

声明使用serviceBase+“api/CustomTemplate/”。感谢:)声明使用serviceBase+“api/CustomTemplate/”。感谢:)声明使用serviceBase+“api/CustomTemplate/”。感谢:)声明使用serviceBase+“api/CustomTemplate/”。谢谢:)