angularJs ng-click控制器内的方法

时间:2014-08-08 14:00:40

标签: c# asp.net-mvc html5 angularjs

我想在ng-click上调用函数Supportticket()在myController里面,但是它不起作用请帮我解决这个问题。 Supportticket()方法在我的javascript文件中的控制器内部 我想在tab1上点击ng来调用它。

app.controller('myController', function ($scope, $http) {
    GetSupportData();
   // GetQCQAData();
        $scope.setSelected = function () {
        // console.log("show", arguments, this);
        if ($scope.lastSelected) {
            $scope.lastSelected.selected = '';
        }
        this.selected = 'rowSelect';
        $scope.lastSelected = this;
    }
    $scope.predicate = '-Date';
    function GetSupportData() {
        blockUI();
        $http({
            method: 'Get',
            url: '/Home/GetSupportData',
        }).success(function (data, status, headers, config) {
            $scope.Support = data.SupportData;

            var fetchedsupportCountLen = data.supportCount.length;
            if (fetchedsupportCountLen > 0) {
                $('#tblSupportticket tr:gt(0)').remove();
                $('#OpenKey').removeClass('KeyOpenIssue');
                $('#OpenKey').addClass('KeyOpen');
                $('#lblOpenCount').html("");
                $('#lblClosedCount').html("");
                $('#lblInProgressCount').html("");
                $('#lblOnHoldCount').html("");
                $('#lblInProgress3DaysCount').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 < fetchedsupportCountLen; i++) {
                    if (i == 0)
                        $('#lblOpenCount').html(' Open (' + data.supportCount[i] + ')');
                    else if (i == 1)
                        $('#lblClosedCount').html(' Closed Today (' + data.supportCount[i] + ')');
                    else if (i == 2)
                        $('#lblInProgressCount').html(' In Progress (' + data.supportCount[i] + ')');
                    else if (i == 3)
                        $('#lblOnHoldCount').html(' On Hold (' + data.supportCount[i] + ')');
                    else if (i == 4)
                        $('#lblInProgress3DaysCount').html(' Inactive for more than 3 working days (' + data.supportCount[i] + ')');



                }
            }
            enablePinning: true;
            unblockUI();
        }).error(function (data, status, headers, config) {
            unblockUI();
            $scope.message = 'Unexpected Error';
        });
    }

    function Supportticket() {
        //$('#tblLegendQcqa').hide();
        createCookie("SelectTab", "Support");
        $('#tblSupportticket tr:gt(0)').remove();
        var sv = getCookie('SelectTab');
        if (sv == 'Support') {
            $('#tblLegendQcqa').hide();
            $('#tblLegend').show();


        }
        else if (sv == 'QCQA') {
            $('#tblLegendQcqa').show();
            $('#tblLegend').hide();
        }
    }




});

这是我的HTML

    <div ng-app="myModule">
<div data-ng-controller="myController">
<ul class='tabs'>
    <li><a href='#tab1'  data-ng-click="Supportticket()" class="tabLI"  id="Tab1_Reload">Support</a></li>
    <li style=""><a href='#tab2'  class="tabLI">QC/QA</a></li>
</ul>
    </div>
    </div>

5 个答案:

答案 0 :(得分:1)

您必须使用$ scope,以便绑定它:

$scope.Supportticket = function() {
    //$('#tblLegendQcqa').hide();
    createCookie("SelectTab", "Support");
    $('#tblSupportticket tr:gt(0)').remove();
    var sv = getCookie('SelectTab');
    if (sv == 'Support') {
        $('#tblLegendQcqa').hide();
        $('#tblLegend').show();


    }
    else if (sv == 'QCQA') {
        $('#tblLegendQcqa').show();
        $('#tblLegend').hide();
    }
}

答案 1 :(得分:0)

您需要将Supportticket函数放入$ scope。

$scope.Supportticket = function () {
        //$('#tblLegendQcqa').hide();
        createCookie("SelectTab", "Support");
        $('#tblSupportticket tr:gt(0)').remove();
        var sv = getCookie('SelectTab');
        if (sv == 'Support') {
            $('#tblLegendQcqa').hide();
            $('#tblLegend').show();


        }
        else if (sv == 'QCQA') {
            $('#tblLegendQcqa').show();
            $('#tblLegend').hide();
        }
    }

答案 2 :(得分:0)

你需要放入范围:

 $scope.Supportticket = function() {
    GetSupportData();
    createCookie("SelectTab", "Support");
    $('#tblSupportticket tr:gt(0)').remove();
    var sv = getCookie('SelectTab');
    if (sv == 'Support') {
        $('#tblLegendQcqa').hide();
        $('#tblLegend').show();


    }
    else if (sv == 'QCQA') {
        $('#tblLegendQcqa').show();
        $('#tblLegend').hide();
    }
}

答案 3 :(得分:0)

尝试将范围与您尝试在单击时调用的函数绑定。 $scope.Supportticket = function(){}

答案 4 :(得分:0)

试试这个:

function Supportticket() {
   //Some of your codes...
   // Then just call the function.
   GetSupportData();
}

希望它有所帮助.......!