我有一个dataservice,我想使用外部npm request包,因为我在Angular $ http中遇到了一些问题
(function () {
angular.module('app').factory('dataservices', dataservices);
/* @ngInject */
function dataservices($state, $rootScope, authService) {
var request = require('request'); // This does not work
var getData = () => {
return new Promise((resolve, reject) => {
request({
url: 'url',
headers: {
'Authorization': 'token'
}
}, (error, response, body) => {
if (error) {
return reject(error);
}
return resolve(response);
});
});
}
}
问题是如何在我的dataService中使用npm请求?