Angularjs包括基于位置的部分

时间:2014-02-11 00:30:52

标签: angularjs location partials

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

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

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

谢谢!

1 个答案:

答案 0 :(得分:1)

在控制器内部,根据位置哈希创建范围项:

$scope.currentHash = location.hash;

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

<div ng-if="currentHash === '#/'" ... >