强制点击事件无需点击即可发生

时间:2014-07-03 10:11:54

标签: javascript angularjs

我在角度js中编写了一个函数,使用ng-click点击任意按钮时调用该函数。我必须在页面加载时调用事件吗?如何在没有click的情况下从js directely调用事件。

$scope.$emit我试过但它无效!!

   $scope.loaddcurrent = function(pagename) {
            console.log('called'+pagename);
            $scope.templateurl = pagename;

            if (pagename == "gallery.html") {
                //Initially loading image data as gallery is initially set to image

                console.log('gallery .html is --------->');
                $scope.images = [];
                $scope.imageCategories = [];
                $scope.currentImage = {};
                $scope.images = Gallery.query({
                    media : "image"
                });

                //Not used below part currently
                $scope.currentImage = _.first($scope.images);
                $scope.imageCategories = _.uniq(_.pluck($scope.images, 'category'));

            }


        };

1 个答案:

答案 0 :(得分:0)

请在带有ng-control的div(或组件)上输入id:

<div id="myControl" ng-control="MyControl">

现在,您可以在dom加载后调用

$(function() {
    angular.element(document.getElementById('myControl')).scope().loaddcurrent();
});

当然,如果你不使用jquery,请调用window.load ...但我更喜欢jquery: - )