Ich bin ziemlich neu bei ES6, aber ich mache jetzt seit einer Weile eckig.Babel versagt es6 zu kompilieren angular factory
Ich verstehe nicht, warum der folgende Code nicht von Babel transpiliert wird. Testen Sie es selbst, indem Sie in https://babeljs.io/ einfügen.
Der Fehler ist, dass es eine (
am Anfang der const singleDocumentSample
erwartet, die ein falsch gemeldeter Fehler zu sein scheint. Ich probierte Variationen von
const xx; xx = {};
nur für den Fall, dass es initialization-related war. Ich habe versucht, zu let
und sogar var
zu wechseln. Was ist los?
Whole-Code-Datei unter:
class FakeData {
constructor($httpBackend) {
'ngInject';
this.$httpBackend = $httpBackend;
}
initialize() {
this.$httpBackend.whenGET('/v1/api/documents').respond(function() {
return [200, getAllDocuments()];
});
this.$httpBackend.whenGET(/\/v1\/api\/documents\/[1-9][0-9]*/).respond(function() {
return [200, getDocumentById()];
});
}
getAllDocuments() {
return allDocumentsSample;
}
getDocumentById() {
return singleDocumentSample;
}
const singleDocumentSample = {
"id": "5728fdb8e4b04adb356afb87",
"fileName": "6454841.xlsx",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"fileExtension": "xlsx",
"uploadDate": "2016-05-03T19:36:24Z",
"thumbnails": [
],
"thumbnailsDetailed": null,
"fileSize": 11467,
"description": "",
"position": null,
"confidential": null,
"customMetadata": null,
"who": {
"creationDate": "2016-05-03T19:36:24Z",
"lastUpdateDate": "2016-05-03T19:36:24Z",
"createdBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
},
"lastUpdatedBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
}
},
"url": "http://attachments-api.apps.wwt.com/api/attachments/5728fdb8e4b04adb356afb87/file"
};
const allDocumentsSample = {
"data": [
{
"id": "5728fdb8e4b04adb356afb87",
"fileName": "6454841.xlsx",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"fileExtension": "xlsx",
"uploadDate": "2016-05-03T19:36:24Z",
"thumbnails": [
],
"thumbnailsDetailed": null,
"fileSize": 11467,
"description": "",
"position": null,
"confidential": null,
"customMetadata": null,
"who": {
"creationDate": "2016-05-03T19:36:24Z",
"lastUpdateDate": "2016-05-03T19:36:24Z",
"createdBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
},
"lastUpdatedBy": {
"userName": "hawkslee",
"fullName": "Hawksley, Emma",
"userId": 49952
}
},
"url": "http://attachments-api.apps.wwt.com/api/attachments/5728fdb8e4b04adb356afb87/file"
}
],
"pagination": {
"page": 1,
"pageSize": 50,
"pageCount": 456,
"sort": "id",
"order": "asc",
"itemCount": 22799,
"nextPageUrl": null,
"previousPageUrl": null
}
};
}
appModule.factory('fakeData', $httpBackend => new FakeData($httpBackend));