2015-11-16 26 views
0

当前任务是为API编写客户端。 $资源模块没有正确注入。我已经将ngResource注入模块,然后将其传递到工厂声明中。然而在控制器内,如果我尝试CONSOLE.LOG($资源),我收到以下错误:

TypeError: 'undefined' is not a function (evaluating '$resource('https://ourlink.nl',options)')

我相信这个问题正在发生的事情/在app.js没有发生,但接受如果您有其他想法,请输入。你能帮我发现问题吗?

restClient.js

function restClient ($resource) { 
    'use strict'; 
    var options = {}; 

    init(); 

    return { 
    endpoint: self.endpoint, 
    sendRequest: sendRequest 
    }; 

    function init() { 
    self.endpoint = 'https://ourlink.nl'; 
    } 

    function sendRequest() { 
    $resource('https://ourlink.nl', options); 
    return true; 
    } 

} 

module.exports = restClient; 

app.js

var angular = require('angular'); 

// imports 
require('angular-resource'); 

(function (angular, config, loaders, controllers, services, providers) { 
     'use strict'; 

     angular 
     .module('at.annabel', [ 
     'ngLocale', 
     'ngRoute', 
     'ngResource', 
     'ngSanitize', 
     'pascalprecht.translate', 
     'ui.bootstrap' 
     ]) 

    // constants 
     .constant('translations', config.translations) 

    // config 
     .config([ 
     '$locationProvider', 
     'config.BASE_PATH', 
     providers.locationProvider 
     ]) 

    // services 
     .factory(
     'restClient', 
     ['$resource', services.restClient] 
    ) 

    // controllers 
     .controller(
     'PlaceholderController', 
     [controllers.PlaceholderController] 
    ) 
    ; 
} 
     ))(
    angular, 
    // config 
    { 
     menu: require('./config/menu').config 
... 
     } 
    }, 
    // loaders 
    { 
     localeLoader: require('./config/locale-loader') 
    }, 
    // controllers 
    { 
     PlaceholderController: require('./modules/placeholder/placeholder-controller') 
    }, 
    // services 
    { 
     restClient: require('./services/restClient') 
    }, 
    //providers 
    { 
     locationProvider: require('./config/location-provider') 
    } 
); 

回答

0

原来在那里的全部时间。由于该应用程序不会在浏览器中调用restClient.js,因此我只在测试中看到该模块被调用。测试运行器没有针对$ resource正确设置,并且$ resource需要通过测试注入到模块中。感谢大家花时间阅读和调查。我抓住了app.js文件,因为它非常传统,但是结果证明整个文件是合法的。