【问题标题】:Why is this function being ignored in Angular? [closed]为什么这个函数在 Angular 中被忽略了? [关闭]
【发布时间】:2015-07-13 14:55:15
【问题描述】:

我正在使用 ngIdlengStorage 来保存某人在超时后输入到页面的数据,这样当他们重新登录时,他们在退出前输入的内容是还在。

我使用以下代码的目标是拥有一个与视图一起加载的函数,该视图确定从何处提取 appSettings 的值(具有页面中所有表单值的 JSON)。所以,我检查$localStorage.idleTimeout 是否为真(只有在用户超时时才应该存储的值)。

我的 JavaScript 如下所示:

var loadLocalStorage = function(){
        if($localStorage.idleTimeout){
            $scope.applicationSettings  = $localStorage.applicationSettings;
            $localStorage.idleTimeOut   = false;
        }
        else{
            $scope.applicationSettings = appSettings;
        }
    }

loadLocalStorage;

有什么问题?当进入调试器时,该函数似乎甚至没有真正尝试,它只是跳过它。即使$localStorage.idleTimeout 没有按应有的方式设置为true,我仍然应该得到$scope.applicationSettings 的值,但可惜事实并非如此。

【问题讨论】:

  • idleTimeout != idleTimeOut 错字?
  • loadLocalStorage()

标签: javascript angularjs ng-idle


【解决方案1】:

看起来您根本没有调用该函数。在js中调用函数,需要括号。试试看:

loadLocalStorage();

【讨论】:

  • ...叹息。谢谢。
猜你喜欢
  • 2022-12-23
  • 2010-10-03
  • 2020-12-17
  • 1970-01-01
  • 2013-09-30
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多