Javascript 使用ui.router呈现的页面的角度JS事件
背景场景: 我有一个Javascript 使用ui.router呈现的页面的角度JS事件,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,背景场景: 我有一个ng repeat,它填充我的视图,动态地放大容器 渲染完成后,我需要调整我的的高度,我还需要在我的应用程序的每个其他页面上进行调整 我非常了解ready()函数: angular.element(document).ready(function() { console.log('ready') }) 但是,放入app.js的这段代码只能在打开(或重新加载)第一页时执行。 重要提示: 我正在使用ui.router浏览我的“页面”,所以每当我
ng repeat
,它填充我的视图,动态地放大
容器
渲染完成后,我需要调整我的
的高度,我还需要在我的应用程序的每个其他页面上进行调整
我非常了解ready()
函数:
angular.element(document).ready(function() {
console.log('ready')
})
但是,放入app.js的这段代码只能在打开(或重新加载)第一页时执行。
重要提示:
我正在使用
ui.router
浏览我的“页面”,所以每当我需要更改页面时,我都会调用“$state.transitiono()”
问题:是否有一个角度事件在页面完全呈现时被广播?在寻找解决方案时,我发现有一个ui.router事件在DOM完全呈现时被调用(在每个新的状态转换时) 事件是
$viewContentLoaded
,语法非常简单:
$rootScope.$on('$viewContentLoaded', function (event) {
console.log('lock & loaded')
})
我认为这可能对其他人有用,
干杯您也可以像这样使用OneNet进行uirouter
$stateProvider
.state('printer',
{
url: "/printer",
views:
{
"view":
{
templateUrl: "/static/tpls/cloud/app/printer.php"
}
},
onEnter: function(){
try {
window.webkit.messageHandlers.pageIn.postMessage("enter printer page");
} catch(err) {
console.log('The native context does not exist yet');
}
},
onExit: function(){
try {
window.webkit.messageHandlers.pageOut.postMessage("leave printer page");
} catch(err) {
console.log('The native context does not exist yet');
}
document.getElementById('liveMovie').style.height='30px';
}
})
对于每个嵌套视图,这似乎都会触发。有没有办法让它在整个页面呈现时只触发一次?我不再关注它了,但整个事情似乎有点混乱。看看这个:我也对它为每个嵌套视图触发感到沮丧。我利用函数来限制它触发的频率,这为我解决了这个问题。