我有登录页面。AngularJs location.path不传递参数
的login.html
<ion-view view-title="Login" name="login-view">
<ion-content class="padding">
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="Username" ng-model="data.username">
</label>
<label class="item item-input">
<input type="password" placeholder="Password" ng-model="data.password">
</label>
</div>
<button class="button button-block button-calm" ng-click="login()">Login</button>
</ion-content>
</ion-view>
当我点击登录按钮login()
方法的工作在下面
LoginCtrl控制器。
.controller('LoginCtrl', function ($scope, LoginService, $ionicPopup, $state, $location, $http) {
$scope.login = function() {
$http({
method: 'GET',
url: 'http://localhost:49431/api/values/GetUserInfo?username=' + $scope.data.username + '&password=' + $scope.data.password + ''
}).then(function successCallback(response) {
if (response.data.Status == true) { // Success
$location.path('/HomePage/').search({ id: '1' }); // Problem here
} else { // Fail
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'Username or password is incorrect!'
});
$scope.data.username = "";
$scope.data.password = "";
}
}, function errorCallback(response) {
alert("error");
});
}
})
我用
$location.path('/HomePage/').search({ id: '1' });
代码以id参数传递给HomePage.Html page.However既不位置路径通参数也无法重定向page.Shortly位置路径是行不通的。
HomePageCtrl控制器
.controller('HomePageCtrl', function ($scope, HomePageService, $state, $location, $cordovaCamera, $stateParams, $routeParams) {
alert($routeParams.id + $stateParams.id);
}
app.js
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('HomePage', {
url: '/HomePage',
templateUrl: 'templates/HomePage.html',
controller: 'HomePageCtrl'
})
.state('login', {
url: '/login',
templateUrl: 'templates/Login.html',
controller: 'LoginCtrl'
});
$urlRouterProvider.otherwise('/login');
});
问:
我怎么能使用传递参数从LoginCtrl控制器HomePageCtrl控制器?
任何帮助将不胜感激。
谢谢。
$ location.path()不会加载新页面。 URL在浏览器中更新还是对$ location.path的调用看起来完全被忽略? –