我在角度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'));
}
};
答案 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: - )