0

刚刚从 Zend Framework 2/jQuery 的工作方式进入 AngularJS。

我在 Zend Framework 中的 layout.html 将包含如下内容:

<html><body>
<div id="topNavigation" class="nav nav-fixed">
<?php
if ($this->identity()) :
    ?>
    <button id="logoutBtn">Log out</button>
    ?>
else:
    ?>
    <input type="text" name="username" />
    <input type="password" name="password" />
    <button>Login</button>
    <?php
<?php
endif;
?>
</div>
<?php 
// The content from each ViewAction
echo $this->content 
?>
<footer>This is the common footer text.</footer>
</body></html>

现在我将其转换为 AngularJS 我了解 index.html 是带有 ngView 指令的布局,指向每个视图的模板文件。如何将变量放入我的布局以切换登录状态?如果你不能真正控制布局,我在哪里保存保持登录状态的代码,因为我在任何地方都看不到全局代码。

我的 angularJS index.html 布局文件目前与上面类似:

<html><body>
<div id="topNavigation" class="nav nav-fixed">
    <button id="logoutBtn">Log out</button>
    <input type="text" name="username" />
    <input type="password" name="password" />
    <button>Login</button>
</div>
<div ng-view></div>
<footer>This is the common footer text.</footer>
</body></html>
4

1 回答 1

1

最好的地方可能在 $rootScope 中,因为所有控制器的范围都继承自它,所以可以将其视为“全局”。

不过,我在上面的 index.html 中看到,您没有指定控制器。您需要添加一个控制器(可能在“body”中),然后在该控制器中,将登录信息添加到 $rootScope.

一旦你的 $rootScope 中有一个变量(比如'isLoggedIn'),你就可以使用 ng-show 和 ng-hide 指令来确定你想要显示的 DOM 的哪些子集。

于 2013-04-01T00:56:23.753 回答