问题
I'm kind of stuck here in this situation, where I need my app to reload when changing from one "project" to another. I've tried many things and I have been searching over and over to find a solution.
My app is kind of complex, and if I try this in an isolated scenario it works perfectly, as it should. http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.directive:ui-sref
<li ng-repeat="project in app.projects" ng-cloak>
<a ui-sref="app.channel({projectId:project.id, channelId: project.channels[0].id})" ui-sref-opts="{reload: true, notify: true}" class="active">
<span>{{ project.name }}</span>
</a>
</li>
Where the important part would be:
ui-sref-opts="{reload: true, notify: true}
In my routes file I have many nested routes and views and I also have a custom authenicator set up. When I strip most of that down, it works. That's why I can't post any code example on Codepen or something similar.
Now my question is, is there any known issue with the UI-Router when using it with an authenticator, or maybe any other reason, why the ui-sref-opts won't reload the page?
Sorry for the kind of unspecific question, but maybe someone can help me out.
EDIT: More information and code
Ok, I'll try my best to give you the relevant information.
This is how my config.router.js is set up.
angular.module('app')
.run(
// Authenicator is in here
)
.config(
['$stateProvider', '$urlRouterProvider', 'JQ_CONFIG', '$authProvider',
function($stateProvider, $urlRouterProvider, JQ_CONFIG, $authProvider) {
// ...
.state('app.channel', {
url: '/projects/{projectId}/{channelId}',
views: {
'': {
templateUrl: 'tpl/channel/index.html'
}
},
resolve: {
deps: ['$ocLazyLoad',
function($ocLazyLoad) {
return $ocLazyLoad.load('angularFileUpload').then(
function() {
return $ocLazyLoad.load([
]);
}
);
}
]
}
})
// ...
}
]
);
回答1:
It could depend on the directive cache-view="false"
. Usually, you have to put it on the <ion-view>
directive in the page you are going, in your case in tpl/channel/index.html
. But if you have nested view, you should put it in every view.
I had the same problem with a nested tab view. I had a series of tab and, inside one of them, another view with two tabs.
<ion-tabs class="tabs-icon-top tabs-color-active-positive">
<!-- Home Tab -->
<ion-tab title="MY FEED" icon-off="ion-ios-home-outline" icon-on="ion-ios-home" ui-sref="main.wall">
<ion-nav-view name="tab-wall"></ion-nav-view>
</ion-tab>
<!-- Messages Tab -->
<ion-tab title="MESSAGES" icon-off="ion-ios-email-outline" icon-on="ion-ios-email" ui-sref="main.message-tabs" ui-sref-opts="{reload: true, notify: true}">
<ion-nav-view name="tab-messages"></ion-nav-view>
</ion-tab>
</ion-tabs>
To make the reload work I had to put the directive cache-view="false"
both in the container
<ion-view cache-view="false">
<ion-tabs class="tabs-color-active-positive tabs-striped tabs-message tabs-top">
<!-- Message Tab -->
<ion-tab title="MESSAGES" ui-sref="main.message-threads" ui-sref-opts="{reload: true, notify: true}">
<ion-nav-view name="subtab-messages"></ion-nav-view>
</ion-tab>
<!-- Notification Tab -->
<ion-tab title="NOTIFICATIONS" ui-sref="main.notifications">
<ion-nav-view name="subtab-notifications"></ion-nav-view>
</ion-tab>
</ion-tabs>
and in the page
<ion-view view-title="Message Threads" class="threads" cache-view="false">
<ion-content class="has-tabs has-tabs-top">
...
来源:https://stackoverflow.com/questions/32661233/angularjs-ui-sref-opts-does-not-help-reloading-the-app