2017-01-09 94 views
1

自從最近2小時以來,我一直在努力處理以下錯誤。我不知道什麼是錯的。AngularJs:「意外的輸入結束」

SyntaxError: Unexpected end of input 
at eval (<anonymous>) 
at Function.globalEval (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:4:4228) 
at init.domManip (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:20866) 
at init.append (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:18502) 
at init.<anonymous> (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:19874) 
at Function.access (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:4:5765) 
at init.html (https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js:5:19537) 
at Object.<anonymous> (http://127.0.0.1:8887/js/angular-ui-router.min.js:7:24156) 
at https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js:16:71 
at ta (https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js:84:35) <div ui-view="" class="ng-scope"> 

,我只能發現,當我稱之爲angjs服務

app.factory("Userservice", ['$rootScope', '$http', 'GENERAL_CONFIG', 'FlashService', 
    function($rootScope, $http, GENERAL_CONFIG, FlashService) { 
     return { 
      FindUserDetail: function(userid) { 
       return $http.get(String.format('{0}/GetUserDetailById?UserId={1}', 
        GENERAL_CONFIG.ServiceWebApiUrl, 
        userid)); 
      } 
     }; 
    } 
]); 

在此之後發生是我的控制器代碼

var userId = loggedIn.userId; 
      Userservice.FindUserDetail(userId).then(//this line throws error 
       function(data) { 
        if (data.data != null || data.data != undefined) { 
         var a = data.data.myJsonVariable //I get valid data here 
        } 
       }, 
       function(httperror) { 
        FlashService.Error("Error Status Is " + httperror.status, true); 
       }); 

輸入意外結束是非常通用的錯誤。 指導我。

+0

它出現時,jQuery是解析您的來電'GetUserDetailById'的響應被扔。它可能會返回一個不完整或無效的json字符串。你能編輯添加來自服務器的響應嗎? – Rhumborl

+0

json響應已完成。當我在json編輯器中解析響應時,它是完整的。解析沒有任何錯誤。即使在成功函數中,我可以訪問json對象。像data.data.myJsonVariable –

+0

你是否在此頁面/控制器實例化時立即調用它?或者這是返回一些函數? – alphapilgrim

回答

1

我想你正試圖根據變量值形成string。你在哪裏試圖利用C#的String.Format功能。在JavaScript中不可用String.Format。或者可能錯過了擴展String原型。

你可以做使用模板文字ES6這裏

return { 
FindUserDetail: function(userid) { 
    return $http.get(`${GENERAL_CONFIG.ServiceWebApiUrl}/GetUserDetailById?UserId=${userid}`); 
} 
};