如何每次你导航到相应的视图/状态时重新运行该控制器? [英] How to re-run the controller every time you navigate to the corresponding view/state?
问题描述
我有一个链接到一个控制器,一个观点:
I have a view that is linked up to a controller:
<div ng-controller="myController">
...
</div>
控制器:
app.controller('myController', ['$scope',
// Some code here that calls a webservice and updates the scope
]);
当控制器最初运行时,它会调用Web服务,返回的数据并将其绑定到的范围。它的伟大工程。然而,当我浏览到另一个视图/状态使用 UI-SREF
或 $ state.go()
和我导航背的这种观点,则控制器不会再次调用web服务。
When the controller initially runs, it calls a webservice, returns the data and binds it to the scope. It works great. However when I navigate to another view/state using ui-sref
or $state.go()
and I navigate back to this view, the controller doesn't call the webservice again.
有没有一种方法,以确保每一个在这个视图和控制器的国有土地,控制器重新执行时间发言?
Is there a way to make sure that every time the state lands on this view and controller, the controller is re-run so to speak?
推荐答案
离子默认缓存视图和控制器执行来提高性能。你可以用缓存禁用:假
:
Ionic by default caches view and controller execution to improve performance. You can disable it with cache: false
:
$stateProvider.state('myState', {
cache: false,
url : '/myUrl',
templateUrl : 'my-template.html'
});
,也可以使用在URL级别禁用它 UI-SREF-OPTS
how把重装选项UI的SREF标记
请参阅缓存文档。
这篇关于如何每次你导航到相应的视图/状态时重新运行该控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!