![](/img/trans.png)
[英]how to pass object data from one controller to another controller in angularjs
[英]pass an object from controller to another controller angularjs
注冊后,如何自動重定向到authentificate頁面並以authenficate.html的形式放置登錄名和密碼?
signupCtrl
demoApp.controller('signupCtrl',function($scope,$http,$location,User) {
User=$scope.user;
$scope.verification = function(isValid,User) {
User=$scope.user;
if (isValid) {
$scope.message = "Submitted ";
console.log(User);
console.log(User.type);
if(User.type=="recruteur")
{
window.alert("bonjour recruteur "+ User.email);
$location.path("/auth");
}
else {
window.alert("bonjour condidat "+ User.email);
$location.path("/auth");
}
} else {
$scope.message = "There are still invalid fields below";
}
};
});
SINGUP.html
<body ng-controller="signupCtrl">
<form name="registrationForm" novalidate
ng-submit="submit(registrationForm.$valid)">
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-group"
ng-model="user.email"
required />
</div>
<div>
<label>Password</label>
<input type="password" name="password"
ng-model="user.password"
required/>
</div>
<div>
<button type="submit" ng-click="verification(registrationForm.$valid,registrationForm.user)">Register!</button>
</div>
</form>
</body>
控制器認證:
demoApp.controller('personCtrl',function ($scope, $http,$location,User) {
console.log(User);
var person=User;
$scope.emaill=person.email;
$scope.pwd=person.password;
console.log(person);
});
認證頁面:
<body>
<form>
<input type="text" ng-model="emaill">
<input type="password" ng-model="pwd">
<input type="submit" value="Connexion" ng-click="connexion(person)">
</form>
</body>
路線提供者
demoApp.config(['$routeProvider',
function($routeProvider){
//systeme de routage
console.log('rederction');
$routeProvider.when ('/auth',{templateUrl: 'authentficate.html',
controller: 'personCtrl'})
.otherwise({redirectTo: 'Signup.html'}
);
}
]);
您可以將會話所需的數據放入服務中。
https://docs.angularjs.org/guide/services
但是不要在其中輸入密碼,僅輸入用戶名和身份驗證令牌。
在此處查看基於令牌的身份驗證的完整示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.