当用户在登录表单处进行了身份验证后,我尝试加载不同的模板。我可能已经找到了问题,我认为这是因为我没有在相同范围内工作。
我在作用域中有一个名为template的属性,当用户成功登录时我会更改它,但这种方法存在问题,因为如果我再次调用AccountCtrl
,模板将被覆盖为登录模板:
var AccountCtrl = WorkerApp.controller('AccountCtrl', function ($scope, $location, AccountService) {
$scope.template = 'Home/Template/login';
$scope.Login = function () {
$scope.template = "Home/Template/register";
};
};
}
});
在我的index.html中,我有一些HTML代码超出了ng-view的范围:
<div class="container">
<div class="header">
<div class="loginView">
<div ng-include="template" ng-controller="AccountCtrl"></div>
</div>
</div>
</div>
我的登录模板
<form name="login" ng-controller="AccountCtrl">
<button class="btn btn-primary btn-sm" ng-click="Login()">Login</button>
{{template}}
</form>
我对Angular并不是很熟悉,无法确定哪种方式是符合Angular的解决方法。在我的模板中,我可以移除ng-controller="AccountCtrl"
,但这样我就无法调用控制器中的登录函数(我已经测试过了)。