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')
}
);