这有效:
<div ng-include="'login.html'" flex ng-if="!loggedIn" ng-controller="LoginController"></div>
但是,这不会({{test}}
不输出任何内容):
<ng-include src="'login.html'" flex ng-if="!loggedIn" ng-controller="LoginController"></ng-include>
有什么理由吗?或者这是一个错误?
登录.html:
<p>{{test}}</p>
登录 Controller :
function LoginController($scope){
$scope.test = 'login';
}
最佳答案
我不太确定“loggedIn”的定义位置,但是当我在父 Controller 上定义它时,两种语法都按预期工作。
<div ng-controller="PrntCtrl">
<div ng-include="'test.html'" flex ng-if="!loggedIn" ng-controller="TestCtrl"></div>
<ng-include src="'test.html'" flex ng-if="!loggedIn" ng-controller="TestCtrl"></ng-include>
</div>
需要考虑的一些问题: 您使用什么版本的 Angular ? 您的应用程序是如何定义的以及 Controller 如何向应用程序注册? “loggedIn”在哪里定义?
关于javascript - AngularJs - 将 ng-controller 与 ng-include 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37128118/