0
var weatherApp = angular.module('weatherApp', ['ngRoute', 'ngStorage']);
weatherApp.config(function ($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'html/views/search.html',
controller: 'searchCtrl',
})
.when('/forecast',{
templateUrl: 'html/views/forecast.html',
controller: 'forecastCtrl',
})
.when('/login',{
templateUrl: 'html/views/login.html',
controller: 'loginCtrl',
})
.when('/logout', {
controller: 'logoutCtrl',
})
.otherwise({
redirectTo: '/',
});
});
註銷控制器角JS +重定向不工作
weatherApp.controller('logoutCtrl', ["$scope", "$location", "$localStorage", function($scope, $location, $localStorage){
$localStorage.removeItem("user_email");
$localStorage.removeItem("user_password");
console.log("coming in logout controller!!");
$location.path("/login");
}]);
我寫上面的代碼來定義我的網站路線。對於註銷,我已將控制器定義爲「logoutCtrl」。但我的代碼似乎不工作。當我點擊SITE_URL /#/ logout時,它不會控制日誌既不刪除localStorage數據。