在AngularJS中,可以使用$location服务来在不同的HTML页面和控制器之间进行导航。以下是一个示例解决方案:
Home
Profile
var app = angular.module('myApp', ['ngRoute']);
app.config(function($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'home.html',
controller: 'HomeController'
})
.when('/profile', {
templateUrl: 'profile.html',
controller: 'ProfileController'
})
.otherwise({
redirectTo: '/home'
});
});
app.controller('HomeController', function($scope) {
// Home controller logic here
});
app.controller('ProfileController', function($scope) {
// Profile controller logic here
});
$location服务来导航到所需的页面:app.controller('LoginController', function($scope, $location) {
$scope.login = function() {
// 登录成功后的逻辑
// 导航到Home页面
$location.path('/home');
};
});
通过以上步骤,你可以在登录成功后使用$location服务在不同的HTML页面和控制器之间进行导航。