![](/img/trans.png)
[英]Onsen-UI ,how to write a javascript , keep ons-scroller at the bottom?
[英]Onsen-UI: how to update the ons-screen page attribute and reload the view?
我刚刚开始使用Onsen UI来实现bootstrap示例 ,我一直在尝试在更改页面属性时让视图更新。
<body ng-controller="PageLoadingCtrl">
<ons-screen page="{{loadedPage}}"></ons-screen>
</body>
我的控制器代码:
app.controller('PageLoadingCtrl', ['$scope', '$timeout', 'notificationService',
function($scope, $timeout, sharedService){
$scope.loadedPage = "index.html";
$scope.updatePage = function(page){
$timeout( function (){
$scope.loadedPage = page;
$scope.$apply();
}, 500);
};
$scope.$on('changePage', function (event, message){
$scope.updatePage(message);
});
}
]);
正如您所看到的,我正在使用body对象上的控制器,以便我可以更新loadedPage变量,但是当我触发changePage事件时,视图不会更改。 使用Web检查器检查DOM元素后,我可以看到页面属性等于我传递给updatePage函数的内容。
到目前为止,我试图用$ apply和$ digest强制刷新,但这仍然不能解决问题。
干杯!
因为ons-screen需要维护页面堆栈。 使用页面属性的绑定并不直观。
使用ons.screen.presentPage()/ dismissPage()/ resetPage()是首选方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.