【问题标题】:How structure my angularjs app如何构建我的 angularjs 应用程序
【发布时间】:2012-07-02 06:03:18
【问题描述】:

我不知道如何在模板中“包含”部分内容。例如,我有一个模板“索引”。当用户导航到“/”时,我喜欢从部分(登录框和其他一些文本 div)重新渲染“索引”上的一些 div,当用户导航到“/newAccount”时,我喜欢在“索引”上重新渲染相同的 div,但是与其他部分。

问题是,这是正确使用 AngularJS 的方式吗?类似于 Facelets 上的包含?

谢谢! ;)

这是我的想法的伪代码:

模板:

<html>
  <body>....{include:mainBox}....{include:foot}...</body>
</html>

/newAccount 的部分内容:

{定义主框}

<div>New user</div>
<div>Username:<input/></div>

{定义脚}

<div>...</div>

更新:

这样的一些是错误的?

function IndexCtrl($scope) {
    $scope.mainPage = 'partials/index/loginbox.html',
    $scope.footPage = 'partials/index/footer.html',
}

在我放的模板之后:

<div ng-include="mainPage"></div>
...
<div ng-include="footPage"></div>

还有路线:

when('/', {
       templateUrl: 'partials/index/layout.html',
       controller: IndexCtrl
   }) 

【问题讨论】:

  • 很好,如果模板 url 永远不会改变,您可以将 url 作为字符串放在 ng-include 中,而无需在 $scope 中创建变量

标签: javascript html templates angularjs


【解决方案1】:

为此使用ng-include。也许你想要的是ng-view + $routeProvider

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 2015-02-18
    • 2017-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多