angularjs - Angularjs:显示旧值的变量范围
问题描述
我将 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);
});
};
});
解决方案
推荐阅读
- raku - 如何传播和捕获 Raku 中另一个线程中抛出的错误?
- c# - C# 中的 ADODB 问题 - 怀疑问题是数据转换
- servicestack - 如何在服务堆栈异常中自定义 HTML 响应?
- mongodb - MongoDB内部数据类型对于相同的值是不同的
- reactjs - ReactJS - 基于输入值 - 自动设置选择选项
- node.js - 为什么即使我的连接是在 HTTPS 上,我也无法访问 Facebook 登录 SDK
- discord - Discord Bot 读取表情符号以分配角色
- powershell - 将索引传递给powershell中的函数
- python-3.x - 在 tkinter 窗口中放置 FigureCanvasTkAgg 的方法?
- wordpress - 将自定义列添加到 wp_posts wordpress db 并使用 wp_insert_post