我做了3个视图并将它们链接到单个控制器。在我的控制器中,我打电话给一个我做过的服务,它可以进行网络调用,并获取一些我应该在前端显示的数据。麻烦的是,尽管我正确地做了一切,但它并没有显示这些数据。来自服务的角度数据没有在前端显示
这就是结构的外观。
路线:
$stateProvider
.state('app.view1', {
url: '/view1',
templateUrl: 'scripts/modules/testModule/views/view1.html',
controller: 'testModuleCtrl',
controllerAs: 'vm',
resolve: {
InitialData: authResolver
}
}).state('app.view2', {
url: '/view2',
templateUrl: 'scripts/modules/testModule/views/view2.html',
controller: 'testModuleCtrl',
controllerAs: 'vm',
resolve: {
InitialData: authResolver
}
}).state('app.view3', {
url: '/view3',
templateUrl: 'scripts/modules/testModule/views/view3.html',
controller: 'testModuleCtrl',
controllerAs: 'vm',
resolve: {
InitialData: authResolver
}
})
控制器:
(function() {
'use strict';
angular
.module('com.module.testModule')
.controller('testModuleCtrl', testModuleCtrl);
testModuleCtrl.$inject = ['$state','$rootScope','UserService', '$stateParams', 'ReportService','SharedDataService','BlogService',
'toastr', 'InitialData', 'SharedFunctionService'];
function testModuleCtrl($state, $rootScope, UserService, $stateParams, ReportService, SharedDataService,BlogService,
toastr, InitialData, SharedFunctionService) {
var vm = this;
vm.getUserData = getUserData;
vm.goToPage1 = goToPage1;
vm.goToPage2 = goToPage2;
vm.goToPage3 = goToPage3;
function goToView1(){
$state.go('app.view1');
getUserData("someArg");
}
function goToView2(){
console.log("Going to View 2")
$state.go('app.view2');
getUserData("someArg");
}
function goToView3(){
console.log("Going to View 3")
$state.go('app.reportView3');
}
function getUserData(argumentType) {
ReportService.GetTestReport("someArg").then(function reportSuccessCallback(result) {
vm.result = result.data;
console.log("CHECK OUT THIS RAD RESULT, BRO ----> ");
console.log(vm.result);
}, function reportErrorCallback(reason) {
vm.reason = reason.data;
console.log("The reason of failure is this --=> ")
console.log(vm.reason);
})
}
}
})();
在HTML中,我试图使这个结果做 {{vm.result}}
但没有显示。我也在管理范围。按照John-Papa Style Guidelines for Angular 1.x中的规定执行所有操作。
从早上起我就开始工作了,我正准备把头发拉出来。我在这里做错了什么?我正在以非常优化的方式尝试一切。 Ps。新来的。
编辑: 根据要求,我也添加了服务代码。
服务
(function() {
'use strict';
angular
.module('com.module.tests')
.factory('ReportService', ReportService);
ReportService.$inject = ['$http','ENV'];
function ReportService($http,ENV) {
var baseUrl=ENV.apiUrl+'/tests/';
var service = {
GetTestReport: GetTestReport
};
return service;
function GetTestReport(type){
return $http.get(baseUrl + type + '/testReport').then(handleSuccess, handleError);
}
// private functions
function handleSuccess(res) {
return res.data;
}
function handleError() {
return {success: false}
}
}
})();
你能告诉我你的ReportService的代码,请。 –
你好@Arno_Geismar我在问题中添加了服务代码。有什么我失踪了吗? – SarthakBatra