角度服务未返回数据
angular service not returning data
我是angular和web项目的新手,我第一次实现服务,我遇到了问题:
var app = angular.module("mdmapp", ['ui.router']);
app.config(function ($stateProvider) {
$stateProvider
.state('creafund', {
url: '/creafund',
templateUrl: '/mdm/html/fundtype.html'
})
.state('creareceipt', {
url: '/creareceipt',
templateUrl: '/mdm/html/receipttype.html'
})
.state('fundentry', {
url: '/fundentry',
templateUrl: '/mdm/html/fundentry.html'
})
.state('payentry', {
url: '/payentry',
templateUrl: '/mdm/html/payentry.html'
})
.state('reports', {
url: '/reports',
templateUrl: '/mdm/html/reports.html'
});
});
app.service('DataServer', function ($rootScope, $http) {
//this function is to get the list of fund types.
this.GetFundType = function () {
$http.get('/mdm/server/app.php/GetFundType')
.then(function (response) {
return response;
});
};
});
//controllers for the various pages and sections.
app.controller('mainctrl', function ($scope, DataServer) {
$scope.FundTypeList = DataServer.GetFundType();
});
app.controller('ftctrl', function ($scope, $http, DataServer) {
$scope.SaveFundType = function () {
var data = {desc: $scope.ftdesc};
$http.post('/mdm/server/app.php/FundTypeCreate', data).success(
function (data, status, headers) {
$scope.ftdesc = null;
$scope.FundTypeList = DataServer.GetFundType();
}
);
};
});
在上面提到的代码中,我无法从"dataever"服务获取数据,它正在从rest api获取json响应。。。将呈现一个表。
您需要等待控制器中的promise,如下所示:
function Factory($http) {
var service = {
GetFundType: GetFundType
};
return service;
function GetFundType() {
return $http.get('/mdm/server/app.php/GetFundType');
}
}
function Controller1($scope,Factory) {
Factory.GetFundType().then(function(response) {
$scope.FundTypeList = response.data;
});
}
相关文章:
- AJAX调用并在Node中获取返回数据
- 角度服务未返回数据
- 统计ajax返回数据中的html元素
- 有没有更好的方法可以测量从Ajax调用返回数据所需的总时间
- Imgur API图像搜索未返回数据
- javascript对象显示为null,但object.properties返回数据
- 如何从ajax调用JQuery返回数据
- 试图从嵌套的回调函数返回数据
- NodeJS FS 不从多个文件返回数据
- ajax函数未在C#中返回数据
- 如何在公共js模块中从web服务返回数据
- 将字符串与 JSON 对象组合以返回数据
- 嵌套异步函数未及时返回数据的问题
- NodeJS JSONStream 以一个长字符串的形式返回数据
- 如何使用 HTML 图像请求将数据发送到服务器,或返回数据作为响应
- 从 Angular 模态服务中的模态主体模板返回数据
- jQuery 每个循环返回数据两次
- $.getJSON 在返回数据后不会运行函数
- 如何访问返回数据中的特定json值
- 工厂返回数据后未设置角度$scope