【发布时间】:2016-12-01 04:54:24
【问题描述】:
我有一个导航栏,它有一个下拉菜单项Log Out,它调用ngPostLogOut() 函数。
在 app.js 中
.when("/logout", {
controller: 'AuthController',
templateUrl: "client/html/auth/logout.html"
});
AuthController
$scope.ngPOSTLogOut = function() {
if ($rootScope.user) {
$rootScope.user = null;
}
if ($window.sessionStorage) {
$window.sessionStorage.clear();
alert('Entered..');
}
alert('Before HTTP');
$http.post('server/auth/logout.php')
.then(function(result) {
$scope.logout = result.data;
});
alert('After HTTP');
/*
$timeout(function() {
$location.path('/');
}, 10000);
*/
};
logout.html
<div ng-controller="AuthController as auth">
<p ng-show='user == null' class="text-center">{{logout}}</p>
<br>
<button ng-click='ngPOSTLogOut()' class="btn btn-default btn-block">Angular To PHP</button>
现在,如果有人从导航栏中的下拉菜单中单击 Log Out 项,则调用该函数。我知道这一点,因为我已经设置了警报并且它们确实会弹出。但是,login.php 中的“回声”没有得到推荐。但是,奇怪的是,如果我按下也调用ngPostLogOut() 函数的Angular to PHP 按钮,则该函数会按预期完美完成。
我的猜测
我的猜测是 ngRoute 强制 Angular 优先考虑 HTML 模板开关,从而使 ngPOSTLogOut() 函数的参数被忽略或解除。
【问题讨论】:
标签: javascript html angularjs ngroute