如何在AngularJS控制器中调用javascript函数?

如何在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.