Angular 1.4.4(基于 Module/Component 的结构)- 无法读取未定义的 属性 'get'(http 未定义)
Angular 1.4.4 (Module/Component based structure) - Cannot read property 'get' of undefined (http undefined)
我正在使用 angular 1.4.4(基于模块的架构)。下面是我的文件结构。我正在尝试从服务 class 调用 rest API(写在 spring-boot 中)。但是,我在 TypeError 中收到错误:无法读取未定义的 属性 'get'。
这是我的控制器class
class ConfigurationController {
/*@ngInject*/
constructor($rootScope, ConfigurationService){
Object.assign(this, {$rootScope, ConfigurationService});
this.name = 'configuration';
let vm = this;
vm.scheduleTimePeriod = 12;
vm.dataTTL=30;
}
loadData() {
this.ConfigurationService.getAllAccessPoint().then((response) => {
console.log(response);
}, (err) => {
console.log(err);} );
}
}
export default ConfigurationController;
这是我的服务class
class ConfigurationService{
/*@ngInject*/
constructor($rootScope, $http, Rest){
Object.assign(this, ($rootScope, $http, Rest));
}
getAllAccessPoint()
{
// return this.Rest.one('/accessPoint/list').getList();
this.$http.get("/configuration")
.then(function successCallback(response){
$rootScope.configuration = response.data;
console.log('load configuration data: ' + $rootScope.configuration);
}, function errorCallback(response){
console.log('Unable to perform get request');
});
return $rootScope.configuration;
}
}
export default ConfigurationService
这个错误听起来像是服务没有正确获取 HTTP 对象,也许它的依赖项丢失了。但是当我直接在控制器中使用它时,一切正常。我错过了什么?
let configurationModule = angular.module('configuration', [
'ui.router',
'ui.bootstrap',
'agGrid',
'kendo.directives'
])
.config(/*@ngInject*/($stateProvider)=>{
$stateProvider
.state('configuration', {
url: '/configuration',
template: '<configuration></configuration>',
ncyBreadcrumb: {
label: 'Configuration'
}
});
})
.service('ConfigurationService', configurationService)
.directive('configuration', configurationComponent);
更改 ConfigurationService
中的以下行
Object.assign(this, ($rootScope, $http, Rest));
到
Object.assign(this, {$rootScope, $http, Rest});
我正在使用 angular 1.4.4(基于模块的架构)。下面是我的文件结构。我正在尝试从服务 class 调用 rest API(写在 spring-boot 中)。但是,我在 TypeError 中收到错误:无法读取未定义的 属性 'get'。
这是我的控制器class
class ConfigurationController {
/*@ngInject*/
constructor($rootScope, ConfigurationService){
Object.assign(this, {$rootScope, ConfigurationService});
this.name = 'configuration';
let vm = this;
vm.scheduleTimePeriod = 12;
vm.dataTTL=30;
}
loadData() {
this.ConfigurationService.getAllAccessPoint().then((response) => {
console.log(response);
}, (err) => {
console.log(err);} );
}
}
export default ConfigurationController;
这是我的服务class
class ConfigurationService{
/*@ngInject*/
constructor($rootScope, $http, Rest){
Object.assign(this, ($rootScope, $http, Rest));
}
getAllAccessPoint()
{
// return this.Rest.one('/accessPoint/list').getList();
this.$http.get("/configuration")
.then(function successCallback(response){
$rootScope.configuration = response.data;
console.log('load configuration data: ' + $rootScope.configuration);
}, function errorCallback(response){
console.log('Unable to perform get request');
});
return $rootScope.configuration;
}
}
export default ConfigurationService
这个错误听起来像是服务没有正确获取 HTTP 对象,也许它的依赖项丢失了。但是当我直接在控制器中使用它时,一切正常。我错过了什么?
let configurationModule = angular.module('configuration', [
'ui.router',
'ui.bootstrap',
'agGrid',
'kendo.directives'
])
.config(/*@ngInject*/($stateProvider)=>{
$stateProvider
.state('configuration', {
url: '/configuration',
template: '<configuration></configuration>',
ncyBreadcrumb: {
label: 'Configuration'
}
});
})
.service('ConfigurationService', configurationService)
.directive('configuration', configurationComponent);
更改 ConfigurationService
Object.assign(this, ($rootScope, $http, Rest));
到
Object.assign(this, {$rootScope, $http, Rest});