如何在代码隐藏的页面加载上触发ng-单击[AngularJS]

时间:2015-03-03 21:14:01

标签: c# asp.net angularjs vb.net

我正在从具有ng-click属性的代码动态生成标签标签,这与链接到单独的js文件中的控制器中的函数。我希望在加载页面时自动触发此ng-click事件。我已经尝试了以下没有运气,

Page.ClientScript.RegisterStartupScript(Master.GetType(), f, "document.getElementById('Element').click();", True)

Page.ClientScript.RegisterStartupScript(Master.GetType(), f, "document.getElementById('Element').triggerHandler('click');", True)

Page.ClientScript.RegisterStartupScript(Master.GetType(), f, "document.getElementById('Element').trigger('click');", True)

1 个答案:

答案 0 :(得分:0)

您需要触发摘要周期才能处理ng-click。

从最合适的人那里检查这个答案,回答任何角度:D

Call Angular JS from legacy code

另请查看此相关小提琴http://jsfiddle.net/peterdrinnan/2nPnB/16/

function externalCall(){
    angular.element($("#microController-div")).scope().incrementDataInService();
}

function baseController($scope, myService) {
    $scope.x = 1;
    $scope.incrementDataInService= function() {

        myService.increase();
        // if you are calling from legacy code, you will need to invoke $apply()
        $scope.$apply();
    }     
    $scope.$on('XChanged', function(event, x) {
        $scope.x = x;
    });        
}
相关问题