Angle joystick control method from external javascript function

I want to access the GetQCQAData () function in the external javascript QCQAIssues () function. GetQCQAData () is defined inside the ng controller. How can i do this? I tried many ways to solve this problem but didn't work.

function QCQAIssues() {
    $('#tblLegend').hide();
    createCookie("SelectTab", "QCQA");
    $('#tblQCQAIssue tr:gt(0)').remove();
}




var app = angular.module('myModule', []);
app.controller('QCQA', function ($scope, $http) {

    //$("[id$='ddlModuleBar']").append('<option  value=0>--------All--------</option>');
    //$("[id$='ddlSystemBar']").append('<option  value=0>--------All--------</option>');

    //GetSupportData();
    fetchSystemInformation();
    fetchModuleSelected();
    GetQCQAData();
    $scope.setSelected = function () {
        // console.log("show", arguments, this);
        if ($scope.lastSelected) {
            $scope.lastSelected.selected = '';
        }
        this.selected = 'rowSelect';
        $scope.lastSelected = this;
    }
    $scope.predicate = '-Date';

    //$scope.GetQCQAData=function(){


    function GetQCQAData() {
     blockUI();

     $http({
            method: 'Get',
            url: '/Home/GetQCQAData',
     }).success(function (data, status, headers, config) {
            $scope.QCQA = data.QCQAData;
            var fetchedQCQACountLen = data.QCQACount.length;


            if (fetchedQCQACountLen > 0) {

                $('#tblQCQAIssue tr:gt(0)').remove();
                $('#OpenKeyQ').removeClass('KeyOpen');
                $('#OpenKeyQ').addClass('KeyOpenIssue');
                $('#lblOpenCountQ').html("");
                $('#lblClosedCountQ').html("");
                $('#lblInProgressCountQ').html("");
                $('#lblOnHoldCountQ').html("");
                $('#lblInProgress3DaysCountQ').html("");
                var sv = getCookie('SelectTab');
                if (sv == 'Support') {
                    $('#tblLegendQcqa').hide();
                    $('#tblLegend').show();
                }
                else if (sv == 'QCQA') {
                    $('#tblLegendQcqa').show();
                    $('#tblLegend').hide();
                }




                for (var i = 0; i < fetchedQCQACountLen; i++) {

                    if (i == 0)
                        $('#lblOpenCountQ').html(' Open (' + data.QCQACount[i] + ')');
                    else if (i == 1)
                        $('#lblClosedCountQ').html(' Closed Today (' + data.QCQACount[i] + ')');
                    else if (i == 2)
                        $('#lblInProgressCountQ').html(' In Progress (' + data.QCQACount[i] + ')');
                    else if (i == 3)
                        $('#lblOnHoldCountQ').html(' On Hold (' + data.QCQACount[i] + ')');
                    else if (i == 4)
                        $('#lblInProgress3DaysCountQ').html(' Inactive for more than 3 working days (' + data.QCQACount[i] + ')');
                }

            }
            enablePinning: true;
            unblockUI();
            //$("[id$='ddlModuleBar']").append('<option  value=0>--------All--------</option>');
        }).error(function (data, status, headers, config) {
            unblockUI();
            $scope.message = 'Unexpected Error';
        });

 }

      

+3


source to share


1 answer


You can do it in various ways: -

Use reuse features as a service

app.service('GetQCQAData' ,function() {
  //your code here
});

      

Then in your outer function

function QCQAIssues() {
     var $injector = angular.injector();
     var GetQCQADataFn = $injector.get('GetQCQAData');
 //your code here
}

      

order

AngularJS $ injector documentation



UPDATED - (added another way)

** Prototype path ** This is not preferred because you cannot guarantee that the controller was executed prior to calling QAQAIssues () (calling vs define - definition is ok)

Your external function

function QCQAIssues() {
  this.GetQCQADate();
  //this will be enhanced later 
  //you must be absolutely sure that QCQAIssues 
  //are called after the controller does its thing
}

      

In your controller

app.controller('QCQA', function ($scope, $http) {
   var GetQCQAData = function () {
     ///your code
   };

    $scope.GetQCQAData = GetQCQAData;

    QCQAIssues.prototype.method = GetQCQAData;// 
}

      

Overall - I would advise you not to mix different namespaces and advise you to find a way to encapsulate your external function inside AngularJS. Think QAQCIssues is in the top level object.

0


source







All Articles