2017-11-01 3 views
-2

わからないいただきました!これで間違っているが、私は生命維持の閉じ括弧を指しているブラウザでこのエラーを取得しておきます。私のAjax呼び出しは、サーバー側から大きなJSONを返します。どんな助けもありがとうございます。AngularJSにSyntaxError:期待される表現、得た「)」

(function() { 
'use strict'; 

angular.module('MenuCategoriesApp', []) 
.controller ('MenuCategoriesController', MenuCategoriesController) 
.service('MenuCategoriesService', MenuCategoriesService) 
.constant('ApiBasePath', "http://sacchis-restaurant.herokuapp.com"); 

MenuCategoriesController.$inject = ['MenuCategoriesService']; 

function MenuCategoriesController (MenuCategoriesService) { 
    var menu = this; 
    menu.logMenuItems = function (shortName) { 
     var promise = MenuCategoriesService.getMenuForCategories(shortName); 

     promise.then(function (response) { 
      menu.categories = response.data; 
     }). 

     catch(function(){ 
     menu.errorText = 'something went terribly wrong!!' 
    }); 
}; 

MenuCategoriesService.$inject = ['$http', 'ApiBasePath']; 

function MenuCategoriesService($http, ApiBasePath) { 
    var service = this; 
    service.getMenuForCategories = function (shortName) { 
     var response = $http({ 
      method: "GET", 
      url: (ApiBasePath + "/menu_items.json"), 
      params : { 
       category : shortName 
       } 
      }); 
     return response; 
    }; 
}; 

})(); 
+1

あなたには余分な '};'があります。 – Pointy

答えて

-1

menu.logMenuItemsの最後に閉じ括弧がありません。以下のコードのコメントを参照してください:

function MenuCategoriesController (MenuCategoriesService) { 
    var menu = this; 
    menu.logMenuItems = function (shortName) { 
     var promise = MenuCategoriesService.getMenuForCategories(shortName); 

     promise.then(function (response) { 
      menu.categories = response.data; 
     }). 

     catch(function(){ 
      menu.errorText = 'something went terribly wrong!!' 
     }); 
    } // ** MISSING THIS CLOSING BRACKET ** 
}; 
+0

次回に質問を投稿する前に、ファイルをクリーンアップし、適切なインデントを使用してください。 –

-1

'menu.logMenuItems'機能で閉じる '}'がありません。

あなたのインデントが閉じcatch約束方式でビットオフになっているようです。

が2つのまたは4のスペースですべてのコードをインデントしてみ...代わりにmenu.logMenuItems機能のcatch呼び出しのために実際に、それはあなたが次の構文エラーを特定するのに役立ちます 終値}); :)また

、設定テキストエディタを使用してJavascript構文をlint(検証)します。

関連する問題