当我尝试测试以重写api / todo时,我的条件不符合任何想法吗?当我尝试测试以重写api / todo时,它不能正常工作我的条件
app.js
.run(function ($rootScope, $location,$log,User) {
$rootScope.$on("$routeChangeStart", function (event,next, current) {
if (!User.signin() && next.authenticate === true){
// User isn’t authenticated
$location.path('/signin');
}
});
service.js
signin: function(data){
return $sails.post('/api/auth',data);
},
控制器
.controller('SigninCtrl', function ($scope,$location,User,$http) {
$scope.signin = function(){
var data={ email:$scope.email,password:$scope.password}
var user=User.signin(data);
//console.log(typeof user);
user.success(function (data) {
//console.log("token signin",data);
var token=data.token;
localStorage.setItem('id_token', token);
$location.path("/todo");
})
.error(function (data) {
//Do whatever is needed
//console.log(data);
});
}
});