$ scope.apply返回类型错误:未定义不是一个函数 [英] $scope.apply returned TypeError: undefined is not a function
本文介绍了$ 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屋!
查看全文