2016-01-20 155 views
0

在我的js应用程序我有通过角UI路由器在这个配置$ stateProvider部分:如何在UI路由器中重构单独的状态和抽象状态?

.state('login', { 
     url: '/login', 
     templateUrl: 'app/login/login.tmpl.html', 
     controller: 'LoginCtrl as login' 
}) 
.state('app', { 
    abstract: true, 
    url: '/', 
    views: { 
     'main': { templateUrl: 'app/main/main.html' } 
    } 
}) 
.state('app.reports', { 
    url: 'reports', 
    views: { 
    '': {templateUrl: 'app/templates/reports.tmpl.html'}, 
    '[email protected]': { 
     templateUrl: 'app/templates/devices.tmpl.html', 
     controller: 'DevicesCtrl as devicesCtrl' 
     }, 
    '[email protected]': {...} 
     } 
    }) 

index.html中我有:

<body ng-controller="MainCtrl as main" > 

    <section ui-view> 
     <div ui-view="main"></div> 
    </section> 
    .... 
    </body> 

它只能如果我有嵌套用户界面 - 在ui-view中查看=“main”。

使用ui-router工作正确吗? 在main.html我有一些页面的页眉,页脚和一些常用信息。 但我有另一个状态,'登录',其中我将拥有自己的模板。但在index.html他们将加载ui-view,而不是ui-view="main"

我如何修改我的index.html和JS避免index.html的嵌套ui-view? 或者我有一个正确的方法?

回答

1

你可以重构你的应用程序的状态是这样的:

.state('app', { 
    abstract: true, 
    url: '/', 
    templateUrl: 'app/main/main.html' 
}) 

这应该让你ONY在您的index.html如下:

<body ng-controller="MainCtrl as main" > 

    <section ui-view> 
    </section> 
    .... 
    </body> 
+0

是的,它的工作! – karl