Angular.js:变量范围显示旧值

时间:2018-06-21 11:40:48

标签: angularjs angularjs-scope

我将userId存储在loginUser函数中,然后使用 getData函数中的userId,但仍然得到未定义的值。

此外,请提出一些有关AngularJs范围的参考。

myModule.controller("loginController",function($scope,$http){
$scope.userId; //define userId

$scope.token;   

$scope.loginUser = function ()
            {
                $http.post(
                    'http://localhost:3000/museum/login',
                    {"email":$scope.username , "password":$scope.password}
                )
                .then(function(response){
                    if(response.status == 200 )
                    {
                        $scope.token = response.data.token;
                        $scope.userId = response.data.userId; //change Value of userId
                        alert ("Login Successful" + $scope.userId);
                        window.open("updateinfo.html","_self");
                    }
                   else{
                           alert ("Login Fail");    
                       }

                });
            };


 $scope.getData = function()
    {
        console.log("Function Called " +$scope.userId); //using userId

        $http.get(
                  'http://localhost:3000/museum/museumDetail/'+$scope.userId,
                  {}
                 )
                 .then(function(response)
                 {
                   console.log(response.data);
                 });
       };
 });

0 个答案:

没有答案