我正在尝试将角度工厂重写为胖箭头功能,但由于在ES6中没有做太多工作,所以我真的很挣扎,所以任何指导都会受到赞赏。
这是我现有的代码:
import angular from 'angular';
import ngResource from 'angular-resource';
export default angular
.module('FlightService', [ngResource])
.factory('FlightService', $resource => {
'ngInject';
const apiUrl = 'https://murmuring-ocean-10826.herokuapp.com/en/api/2';
return $resource('', {}, {
getAirportData: { method: 'GET', url: `${apiUrl}/forms/flight-booking-selector` },
queryFlights: { method: 'GET', url: `${apiUrl}/flights/from/:departure/to/:destination/:startDate/:endDate/250/unique` },
});
}).name;
预期结果:
export const FlightService = () => {
// missing code
}
我的尝试如下:
export const FlightService = () => {
'ngInject';
constructor($resource) {
const apiUrl = 'https://murmuring-ocean-10826.herokuapp.com/en/api/2';
var FlightService = $resource('', {}, {
getAirportData: {
method: 'GET',
url: `${apiUrl}/forms/flight-booking-selector`
},
queryFlights: {
method: 'GET',
url: `${apiUrl}/flights/from/:departure/to/:destination/:startDate/:endDate/250/unique`
},
});
return FlightService;
}
}
这不起作用,我在这个小胡子上遇到意外的令牌错误:
constructor($resource) {
任何帮助都非常感激,因为它让我在最近几个小时内陷入困境。