0

控制器内部的代码是:

(function(){
    $scope.show();
    profile.friend_requests_to_me_service(loggedInUser.id).then(function(data){
        console.log(data);
        $scope.friend_requests_to_me = data.data.friend_request_to_me;
        $scope.friends = data.data.people_you_may_know;
        $scope.hide();
    });   
})();

如您所见,此函数正在调用服务配置文件和该服务的方法。问题是此调用函数不起作用。给出错误: TypeError: (intermediate value)(...) is not a function。在 plunker 中,我检查了一个琐碎的自调用函数。这是链接:http: //jsfiddle.net/Lvc0u55v/4582/。这个微不足道的自调用功能正在工作。但我不明白为什么我的实际应用程序自调用功能不起作用。谢谢您的时间。

目前的工作版本(非自调用)是: $scope.friendship_requests_to_me_function = function(){ $scope.show(); profile.friend_requests_to_me_service(loggedInUser.id).then(function(data){ console.log(data); $scope.friend_requests_to_me = data.data.friend_request_to_me; $scope.friends = data.data.people_you_may_know; $scope.hide(); });
} $scope.friendship_requests_to_me_function();

4

1 回答 1

1

很可能您的 js 语句中缺少一个 ';' 在最后。

尝试添加一个';' 在你的自调用函数之前

在这里阅读更多

我们最终将第二个函数作为参数传递给第一个函数,然后尝试将第一个函数调用的结果作为函数调用。第二个函数将在运行时失败并出现“...不是函数”错误。

于 2016-05-27T13:44:01.167 回答