Javascript函数预期标识符

时间:2016-04-28 12:56:46

标签: javascript angularjs visual-studio-2013

angular.module("myapp", [])

   .controller("UsersController", function (testFactory, $scope) {

       $scope.post = function () {

           testFactory.getApiValue("123");

       }

       $scope.change = function () {

           testFactory.getApiValue($scope);
       }   

 .factory("testFactory", function($http) {
        return
          {
           getApiValue: function(token)
             {
                 return $http.post('api/Printers/1');
          }
       }
    })

代码有效,但Visual Studio告诉我有Expected Identifier错误。

此代码有什么问题吗?

请告诉我应该怎么做才能消除此错误。

1 个答案:

答案 0 :(得分:0)

对于getApiValue功能,您未使用预期的token参数。这不是一个大问题,但您应该能够通过删除未使用的参数或使用该函数中未使用的参数来修复它。

例如:

.factory("testFactory", function($http) {
    return
    {
        getApiValue: function() // <---  Token is removed
        {
             return $http.post('api/Printers/1');
        }
    }
})