【问题标题】:Angular $http.put entries disappear upon page refreshAngular $http.put 条目在页面刷新时消失
【发布时间】:2015-02-19 12:33:15
【问题描述】:

我有以下型号:

var ThingSchema = new Schema({
  name: String,
  info: String,
  active: Boolean,
  date: Date,
  hideFromUser: [String]
});

还有以下方法:

$scope.hideThing = function(thing) {
  $http.put('/api/things/' + thing._id, {hideFromUser: [$scope.getCurrentUser().email]});
};

我想要做的是对于某件事。_id,我希望将当前用户的电子邮件地址放在“hideFromUser”字符串数组中。

这行得通,我看到用户的电子邮件被插入到字符串数组中,但是当我在我的 Web 应用程序上刷新页面或转到新页面时,该数组变回为空。

【问题讨论】:

    标签: javascript angularjs mongoose


    【解决方案1】:

    Angular 纯粹是客户端。它不会在客户端存储任何东西(除非你把它放在 localStorage 或 sessionStorage 中)。

    由于数组存储在客户端,您需要向服务器(或本地/会话存储)询问已在每个页面重新加载事件(刷新或重新加载)中添加的电子邮件。

    【讨论】:

      猜你喜欢
      • 2019-03-18
      • 2017-11-22
      • 2013-07-16
      • 2012-09-21
      • 2020-08-28
      • 2015-11-17
      • 1970-01-01
      • 2011-07-14
      • 2021-12-20
      相关资源
      最近更新 更多