$ scope.apply返回类型错误:未定义不是一个函数 [英] $scope.apply returned TypeError: undefined is not a function

查看:464
本文介绍了$ scope.apply返回类型错误:未定义不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    $http({
        url: "php/insert.php",
        method: "POST",
        data: {
            'myId': myId
        },
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }).success(function (data, status, headers, config) {

        $scope.$apply(function () {
            $scope.currentId = data;
        });

    }).error(function (data, status, headers, config) {});

    $scope.tabs.push({
        "currentId": $scope.currentId
    });

我尝试使用$ scope.apply来更新我的bind-ED $ scope.currentId但它返回返回类型错误:未定义是不是我的$ scope.apply功能,任何想法有什么错在这里。

I try to use $scope.apply to update my bind-ed $scope.currentId but it returned returned TypeError: undefined is not a function for my $scope.apply, any idea what's wrong here?

推荐答案

您不能使用 $适用 $ HTTP ,因为 $ HTTP 它自会包住code与 $适用并调用 $ $适用应用将抛出错误。

You can't use $apply in $http because $http it self will wrap your code with $apply and calling $apply in $apply will throw error.

您code应该是这样的。

your code should be like this

.success(function (data, status, headers, config) {
        $scope.currentId = data;
})

这篇关于$ scope.apply返回类型错误:未定义不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆