本文介绍了如何在AngularJS控制器中调用javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下Javascript函数
I have below Javascript functions
<script type="text/javascript">
function ShowProgress() {
var modal = $('<div />');
modal.addClass("spinmodal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}
function HideProgress() {
var loading = $(".loading");
loading.hide();
$(".spinmodal").remove();
}
</script>
现在我要调用此 ShowProgress()
和 Angular控制器中的HideProgress()
。我想在调用 deletePrepared
并且 HideProgress()
低于 GetAllPrepared
。
now I want to call this ShowProgress()
and HideProgress()
in Angular controller. I want to call ShowProgress()
as soon as deletePrepared
invoked and HideProgress()
below GetAllPrepared
.
<script type="text/javascript">
app.controller("myCntrl", function ($scope, angularService, $modal) {
$scope.deletePrepared = function (itm) {
var getData = angularService.DeletePrepared(itm.ProductId);
getData.then(function (msg) {
GetAllPrepared();
}, function () {
alert('Error in Deleting Record');
});
}
});
</script>
推荐答案
只需调用这些方法:
app.controller("myCntrl", function ($scope, angularService, $modal) {
$scope.deletePrepared = function (itm) {
ShowProgress();
var getData = angularService.DeletePrepared(itm.ProductId);
getData.then(function (msg) {
HideProgress();
GetAllPrepared();
}, function () {
alert('Error in Deleting Record');
});
}
});
提示:使用Angular指令进行DOM操作,不需要任何jQuery代码进行DOM操作,Angular就足够了。
Tip: Use Angular directives to do DOM manipulation and you don't require any jQuery code for DOM manipulation, Angular is sufficient for it.
这篇关于如何在AngularJS控制器中调用javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!