从内部函数更改AngularJS范围变量 [英] Changing AngularJS scope variables from an inside function
本文介绍了从内部函数更改AngularJS范围变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Angular的新手,我试图通过控制器内部的函数更改(或设置)范围变量.这是我的代码:
Hie I am new to Angular and I'm trying to change (or set) the scope variables from a function that is inside a controller. Here is my code:
$.ajax({
type: "POST",
url: URL,
data: param = "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
$scope.modalStatus = 'success';
$scope.modalIcon = 'check';
$scope.modalMessage = 'Invoice Saved!';
showNotification();
}
function errorFunc() {
alert('error');
}
$ scope.modalStatus,$ scope.modalIcon和$ scope.modalMessage是在控制器开始时较早设置的作用域变量.我该如何通过successFunc方法更改它们,请帮忙.
$scope.modalStatus, $scope.modalIcon and $scope.modalMessage are the scope variables that were set earlier at the beginning of the controller. How do I change them in that successFunc method, please help.
推荐答案
更改成功回调:
function successFunc(data, status) {
$scope.modalStatus = 'success';
$scope.modalIcon = 'check';
$scope.modalMessage = 'Invoice Saved!';
showNotification();
$scope.$apply();
}
在一个应用程序中使用jQuery和Angular也是一种不好的做法.Angular为请求提供 $ http .
Also it's a bad practise to use jQuery and Angular in one application. Angular provides $http fo requests.
这篇关于从内部函数更改AngularJS范围变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文