我有一个函数,我想在页面内容加载后调用它。我读到过关于$viewContentLoaded的文章,但它对我不起作用。我在找像这样的东西
document.addEventListener('DOMContentLoaded', function () {
//Content goes here
}, false);
上面的调用在AngularJs控制器中不起作用。
发布于 2015-05-22 20:15:22
您可以通过在HTML元素后添加{{YourFunction()}}
来直接调用它。
这是一个Plunker Link
。
发布于 2016-02-26 18:18:45
在处理google图表时,我不得不实现这个逻辑。我所做的是在我的html内部控制器定义的末尾添加了。
<body>
-- some html here --
--and at the end or where ever you want --
<div ng-init="FunCall()"></div>
</body>
在该函数中,只需调用您的逻辑。
$scope.FunCall = function () {
alert("Called");
}
发布于 2017-01-24 12:15:46
var myM = angular.module('data-module');
myM.directive('myDirect',['$document', function( $document ){
function link( scope , element , attrs ){
element.ready( function(){
} );
scope.$on( '$viewContentLoaded' , function(){
console.log(" ===> Called on View Load ") ;
} );
}
return {
link: link
};
}] );
上面的方法对我很有效
https://stackoverflow.com/questions/21715256
复制相似问题