angularjs 嵌套布局如何实现?

是这样的,我的应用分为前台(home)和用户后台(user),按照基础教程index.html作为首页,同时也作为全局layout。

我的项目大致结构如下:

app
    app.js
    routes.js
    views
        home
            about
                index.html
            login
                index.html
            layout.html
        user
            dashboard
                index.html
            articles
                index.html
                detail.html
            layout.html
    index.html

现在我想的是,views/home 下的模板都继承 views/home/layout.html,同理views/user。
以views/home/about/index.html为例,路由url是这样的:

$routerProvider.when("/about",{
    templateUrl : "views/home/about/index.html"
});

现在的问题是,app/views/home/about/index.html 直接继承了 app/index.html,而我想让它这样继承:

app/views/home/about/index.html -> app/views/home/layout.html -> app/index.html -> 输出到浏览器

该如何实现呢?

======
我找到了一个叫做 angular-ui-router 的第三方插件,它可以替代angular-router,可以实现这个功能。

阅读 4.7k
3 个回答

你的选择是对的。

看起來跟 MEAN.JS 的結構很像,可以參考看看。

把页面里所有元素都做成 directive,把继承和嵌套的关系放在 directive 里,一个页面组合的运用几个 directive。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进