在刷新时重置值?

时间:2019-05-11 03:36:49

标签: javascript html angularjs

我正在用angularjs实现登录表单,并且登录失败或成功时都会弹出引导警报。 问题是刷新页面时,弹出窗口始终位于此处。

这是我的html:

df %>%
  group_by(group) %>%
  mutate(newValue=date[speed==4L])
#> # A tibble: 9 x 4
#> # Groups:   group [3]
#>   group  date speed newValue
#>   <dbl> <dbl> <dbl>    <dbl>
#> 1     1     1     3        2
#> 2     1     2     4        2
#> 3     1     3     3        2
#> 4     2     4     4        4
#> 5     2     5     5        4
#> 6     2     6     6        4
#> 7     3     7     6        8
#> 8     3     8     4        8
#> 9     3     9     9        8

当任一页面处于以下状态时,如何隐藏它们:

  1. 第一次加载或
  2. 刷新

2 个答案:

答案 0 :(得分:1)

请记住,当您为视图或控制器设置scope时,该scope的第一个值为false

例如,scope.loggedin首先是false,直到在您的控制器中将其更改为true

解决方案:

控制器:

scope.login = function(){
  scope.tryToLoginIn = true;

  //..your code : this is just example
  $http.get("loginApi").then(function(respponse){
     if(respponse.status === 200){
        scope.loggedin = true;
     }
  })
}

HTML:

<div class="alert alert-success" role="alert" ng-if='tryToLoginIn && loggedin'>
  Logged in successfully!
</div>

<div class="alert alert-danger" role="alert" ng-if='tryToLoginIn && !loggedin'>
  Log in failed!
</div>

在这里,我们检查tryToLoginIn是否为true,然后开始检查loggedin条件以显示弹出警报。

答案 1 :(得分:0)

似乎您需要另一个参数来检测是否进行了登录尝试。

<div class="alert alert-success" role="alert" ng-if='!anonymous && loggedin'>
  Logged in successfully!
</div>
<div class="alert alert-danger" role="alert" ng-if='!anonymous && !loggedin'>
  Log in failed!
</div>

您将需要以某种方式将这些数据保留在浏览器中,并分别填充匿名参数和登录参数。选项是“ cookie,html5存储”

相关问题