2017-05-09 14 views
0

私はes6でかなり新しいですが、私はしばらくの間角度をつけています。Babelがes6 angular factoryをコンパイルできませんでした

以下のコードがなぜBabelによって翻訳されないのかわかりません。 https://babeljs.io/に貼り付けて自分でテストしてください。

const singleDocumentSampleの先頭にある(が間違って報告されたエラーのように見えるというエラーです。私は、それが初期化に関係していた場合のために、

const xx; xx = {}; を試してみました。 let、さらにvarに変更しようとしました。何が起こっている?

以下のコード全体のファイル:

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));

答えて

1

あなたはあなたのコードの構文エラーを持っている... - クラス本体でのconst宣言を持つことが許されていません(現在の構文であなただけ定義することができますそこのメソッド)。

代わりに、このconstをオブジェクトプロパティとして宣言するか、またはクラス宣言からそれを移動する必要があります。

関連する問題