Javascript $scope.apply返回的TypeError:undefined不是函数
我尝试使用$scope.apply更新绑定的$scope.currentId,但它返回了TypeError:undefined不是我的$scope.apply的函数,你知道这里出了什么问题吗?你不能在Javascript $scope.apply返回的TypeError:undefined不是函数,javascript,angularjs,Javascript,Angularjs,我尝试使用$scope.apply更新绑定的$scope.currentId,但它返回了TypeError:undefined不是我的$scope.apply的函数,你知道这里出了什么问题吗?你不能在$http中使用$apply,因为$http本身会用$apply包装你的代码,在$apply中调用$apply会抛出错误 您的代码应该是这样的 $http({ url: "php/insert.php", method: "POST", dat
$http
中使用$apply
,因为$http
本身会用$apply
包装你的代码,在$apply
中调用$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(函数..可能重复@ZackArgyle错误:[$rootScope:inprog]@Phil根本没有答案,不是吗work@user3522457:为什么使用
$apply()
?$http
具有角度上下文感知功能,将自动消化您的更改。
.success(function (data, status, headers, config) {
$scope.currentId = data;
})