【问题标题】:Why does ng-hide and ng-show not work?为什么 ng-hide 和 ng-show 不起作用?
【发布时间】:2016-10-18 04:01:36
【问题描述】:

美好的一天。我使用了几种方法来使用 ng-show 和 ng-hide,但它们都不起作用。单击按钮时,第一个 div 应该隐藏并出现第二个。请帮帮我!这是我尝试的最后一种方式:

<div class="parentDiv .col-lg-">
    <from class="centerMain">
        <div ng-show="showF" class="center-block">  <!-- this div should hides -->
            <div>
                <label  class="center-block">Введите PIN</label>
            </div>
            <div>
                <input name="userName" placeholder="1234" class="center-block inputLine">
            </div>          
            <div>
                <button ng-click="showF = !showF" class="center-block buttonBig">Установить PIN</button> <!-- this button makes hiding -->
            </div>
        </div>
        <div ng-show="!showF" class="center-block"> <!--this should appears -->
            <div>
                <label  class="center-block">Подтвердите пин</label>
            </div>
            <div>
                <input name="userName" placeholder="1234" class="center-block inputLine">
            </div>          
            <div>
                <button class="center-block buttonBig">Подтвердить</button> 
            </div>
        </div>
    </from>
</div>

【问题讨论】:

  • 如果这实际上是 Angular2 则没有 ng-showng-hideng-click ...
  • @GünterZöchbauer 哦,原来如此。谢谢你。

标签: html angularjs angular


【解决方案1】:

Angular 2 已经弃用了许多不必要的 Angular 1 指令。

您可以使用[hidden]/[ngIf],例如[hidden]="showF"*ngIf="showF"

此外,所有基于事件的指令都已弃用,您可以通过将事件名称包装在 (eventName) 中来直接调用 DOM 上的事件

(click)="myFunction()" //instead of ng-click
(focus)="myFunction()" //instead of ng-focus

【讨论】:

    猜你喜欢
    • 2015-06-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 2018-08-01
    • 1970-01-01
    相关资源
    最近更新 更多