2014-09-24 85 views
2

可能是整个布局错了,但这里是我的情况,我正在使用Angular ui-router的Meanjs.org堆栈。Angular ui路由器重载ng-include外部ui-view

我有一个布局是这样的:

<div data-ng-include="'/modules/core/views/header.client.view.html'"></div> 

<div id="page-content" class="clearfix" fit-height> 
    <div id="wrap" data-ui-view="" class="mainview-animation"></div> 
</div> 

现在我需要重新加载控制器header.client.view.html内部时,我改变$状态。

例如,当我在登录页面并登录时,我需要重新加载头控制器,但由于ui-router仅使用相对模板更改了ui-view部件,因此无法执行此操作:

// this change only ui-view, doesn't care about the ng-include before  
state('home', { 
    url: '/', 
    templateUrl: 'modules/core/views/home.client.view.html', 
}); 

我发现的可能性更多的UI视图添加到状态,所以我可以用于报头添加的UI-视图2代替使用纳克 - 包括但此是指具有在每个状态下的UI的视图2。

有什么建议吗?

回答

2

每次状态改变时,您可能不需要“重新加载控制器”,而是让您的控制器对动态状态变化作出反应并更新其属性。

查看ui路由器$stateChangeSuccess event

2

首先,在你需要听@Matti Virkkunen 这是更好地倾听你的头的控制器的状态“$ stateChangeSuccess”

所以,你只需要声明一个控制器,你的头。并在你的头控制器添加这样的东西。

$scope.$on('$stateChangeSuccess', function() { 
    // Do what you want for example check if the current state is home with $state.is('home'); 
}); 

不要忘了在你的模板来声明控制器

<div data-ng-controller="HeaderController" data-ng-include="'/modules/core/views/header.client.view.html'"></div> 

<div id="page-content" class="clearfix" fit-height> 
    <div id="wrap" data-ui-view="" class="mainview-animation"></div> 
</div>