0
只需進入來自Zend Framework 2/jQuery工作方式的AngularJS即可。AngularJS - 用於交換登錄/我的賬戶部分的變量
我的Zend框架內的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>
啊對不起,我沒有添加控制器的東西。我認爲ngView是你的控制器模板加載的地方。因此,沒有任何地方可以放置這樣的東西,而只需在每個控制器中引用$ rootScope。嗯不錯!謝謝:) –
HTML中的任何元素都可以有一個控制器,它非常方便。如果在這些元素的子元素中定義了另一個控制器,則該控制器將從其父元素繼承。 –