角度ui-router状态子视图在编辑后不更新

时间:2016-06-11 21:16:17

标签: angularjs angular-ui-router

当我从子状态更改模板时,我再次进入视图,第一次加载(因此在模板更新之前)视图已被给出。

我用google chrome测试了它。互联网浏览器,微软边缘所有相同的问题。

我的州

    $stateProvider
        .state('games', {
            abstract: true,
            url: "/?username&token",
            templateUrl: "games/views/Games.html",
            controller: 'GamesController'
        })
        .state('games.open', {
            url: '',
            templateUrl: "games/views/GamesOpen.html"
        })
        .state('games.active', {
            url: "/active",
            templateUrl: "games/views/GamesActive.html"
        })

HTML

    <a ui-sref=".open"><button>open games</button></a>
    <a ui-sref=".active"><button>active games</button></a>
    <div ui-view></div>

问题似乎是视图被缓存,转换工作完美只有我无法查看更新的模板并始终看到加载的第一个加载的模板而且从未更新版本..

A similair question通过在网址末尾添加?&#39; + new Date()来解决此问题,但这看起来像是黑客攻击。

1 个答案:

答案 0 :(得分:0)

你的游戏中没有任何网址。开启状态:请检查一下。我猜这是一个问题。

当我创建应用时

我使用了这段代码:

(在我的特定应用程序中就是这样)

app.config(function($stateProvider,$urlRouterProvider){

$stateProvider.state('list',{
   url:'/list',
 templateUrl:'templates/list.html'
});


$stateProvider.state('edit',{
   url: '/edit/:noteId',
    templateUrl: 'templates/edit.html',
    controller:'EditCtrl'
});

$stateProvider.state('add',{
       url: '/add',
      templateUrl: 'templates/edit.html',
      controller:'AddCtrl'
    });

$urlRouterProvider.otherwise('/list');

});

并使用 像这样的按钮:

 <a href="#/add" class="button button-assertive ion-left ion-compose">New Note</a>