【问题标题】:Angularjs including partials based on locationAngularjs包括基于位置的部分
【发布时间】:2014-02-11 09:48:55
【问题描述】:

我想在我的 index.html 中包含不同的标题,一个用于用户登录时,一个用于用户未登录时。这是我的想法:

<script>console.log(location.hash === '#/')</script>
<div ng-if="location.hash === '#/' " id="header" ng-include="'partials/homeHeader.html'"></div>

控制台打印 true,但 ng-if 中的部分不能正常工作。我该如何解决这个问题,或者有更好的解决方案吗?

谢谢!

【问题讨论】:

  • location 很可能不在导致您的问题的scope 上。

标签: angularjs location partials


【解决方案1】:

在您的控制器中,根据位置哈希创建一个范围项:

$scope.currentHash = location.hash;

然后在你的视图中使用范围项:

&lt;div ng-if="currentHash === '#/'" ... &gt;

【讨论】:

    猜你喜欢
    • 2014-09-05
    • 2016-01-08
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 2014-02-08
    • 2011-07-21
    • 2011-01-20
    相关资源
    最近更新 更多