【问题标题】:Angular template within template模板内的角模板
【发布时间】:2014-10-26 04:16:46
【问题描述】:

让我们看看我是否可以在这里描述我的设置...

我正在设计一个有角度的应用程序,到目前为止,一切都是一页。基本上,当用户点击一个按钮时,控制器会设置哪个

"<ng-include>"

标签可见。所以我的 html 看起来像这样。

<html ng-app= "myApp">
    <head>
        <!-- header stuff -->
        <!-- all the includes and everything -->
    </head>

    <body>
        <div>
            <!-- page nav bar, its a lot of html but it works -->
        </div>

        <!-- content area -->
        <div ng-show= "showHome">
            <ng-include= "home.html">
        </div>
        <div ng-show= "showProfile">
            <ng-include= "profile.html">
        </div>
        <!-- etc... -->

    </body>
</html>

然后在我的控制器中,我只是根据需要设置正确的“showHome”、“showProfile”等。我的问题是,这似乎是一种糟糕的扩展方式,这是我第一次尝试这样的应用程序。

所以重申一下。我想给用户一个单页应用程序的外观,同时交换 html 模板。有任何想法吗?多页也可以,但我想在每一页的顶部保留相同的导航栏。

【问题讨论】:

  • 为什么不使用 UI 路由。 joelhooks.com/blog/2013/07/22/…
  • 转到文档网站上的教程,了解 ng-view$routeProvider 的工作原理
  • 谢谢大家。这是一个很好的第一步
  • 对大家来说,我应该提一下这个应用程序使用了一个flask/jinja后端,虽然我不确定它的区别。

标签: javascript angularjs templates single-page-application partials


【解决方案1】:

我会改用ui-router

它是 ngRoute 的流行替代品,并且非常好地支持嵌套模板。

【讨论】:

  • ui-router 有很多 ngRoute 目前缺乏的强大特性和功能
猜你喜欢
  • 1970-01-01
  • 2016-02-15
  • 2013-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多