angularjs获取数据服务

这些天,有在asp.net web Site㠌入angularjs。
在表单设计时,一些静态数据往往需要从数据库读取。
简化代码,Insus.NET把其重构成一个Service。数据服务或angularjs工厂直接调用即可。

2026-08-18_08-13-22

'use strict';

eamApp.service('fetchService', ['$http', function ($http) {
    this.fetchData = function (url, args) {
        return $http({
            method: 'POST',
            url: url,
            dataType: 'json',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            data: JSON.stringify(args)
        }).then(function (response) {
            return response.data;   // 返回响应数据
        });
    };
}]);
fetchService.js

 

如何调用?
在数据服务中,
2026-08-18_08-24-50

 

在数据工厂中,
2026-08-18_08-48-58

 

想了解有关service & factory区别,可以搜索。

 





posted @ 2026-08-18 09:12  Insus.NET  阅读(1)  评论(0)    收藏  举报