[Asp.net-MVC]angularJs ng-click 为控制器的方法

发布时间: 2016/9/30 0:50:35
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我想要调用的函数位于 myController 的 Supportticket() ng-click 但它不工作,请帮我对于这件事。 Supportticket() 的方式里面我 javascript 文件中的控制器,需要对 ng-click 上 tab1。

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>

解决方法 1:

你需要放入 $scope 的 Supportticket 函数。

$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();
        }
    }
官方微信
官方QQ群
31647020