javascript - 为什么即使使用自定义指令,Angular ng-cloak 也会覆盖我的 ng-show

标签 javascript css angularjs

我试图在登录时隐藏我的布局页面,我将 ng-show 设置为一个 bool 值,当成功登录时该值会设置为 true。无论我做什么,布局页面都不会显示其自身。我遵循了这个 Angular ng-show directive doesn't work for button 的答案但我仍然无法显示页面。当我查看开发工具时,我可以看到正在应用我的自定义样式

HTML代码:

<div class="my-hidden-xs container" ng-show="isLoggedIn">

CSS:

.my-hidden-xs {
    display: none !important;
}

Controller :

function LogInController($scope, $http, $state) {
    $scope.isLoggedIn = false;     
    $scope.signOn = function () {
        $http.post('http://localhost:a location on my backend').then(function (response) {
            if (response.data.token) {
                $scope.$apply.isLoggedIn = true;
                $state.go('main'); 
                //...          

我在这里做错了什么?我是 Angular 的新手,但之前使用过 hide 和 show 没有这个问题。

最佳答案

你能尝试改变你的 css 你有 display: none !important 并且我看不到任何在成功函数上改变它的代码 你可以使用这样的东西:

<div class="container {{checkVisible(isLoggedIn)}}">

在 Controller 中

$scope.checkVisible()
{
 if(isLoggedIn)
      return '';
 else
      return 'my-hidden-xs';   
}

关于javascript - 为什么即使使用自定义指令,Angular ng-cloak 也会覆盖我的 ng-show,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27127990/

相关文章:

python - 如何去除html中的特殊字符

javascript - Http get 请求的完成时间晚于范围在 Angular JS 中获取值的时间

Javascript 对象删除 - 删除另一个对象

javascript - 为什么 jQuery 不能处理附加内容?

javascript - ng-init 没有按预期工作

javascript - 如何让内容根据点击显示和隐藏内容

css - :nth-child(1) versus :first-child in css pseudo selectors are there any merits in choosing one method over the other?有什么区别

css - 文本对齐 : justify doesn't work

javascript - AngularJS 1.2 - 基于左滑或右滑的不同动画

javascript - 如何将推特时间轴嵌入到 Angular4 应用程序