簡體   English   中英

使用ng-click更改按鈕中的文本

[英]Change Text in a button using ng-click

我正在嘗試使用角度更改按鈕中的文本我已經完成了但我有幾個問題。

首先,我的代碼只是在第一次點擊時更改了文本,如何在第二次點擊后再次更改? 那個按鈕隱藏了一個<DIV> ,這就是改變的原因?

角度:

 angular.module('test',[])
    .controller('MyCtrl',function ($scope) {
      $scope.myText = 'Press to start';
      $scope.start = function () {
      $scope.myText = 'Starting...';
    }
});

HTML:

<body ng-controller="MyCtrl">
    <button ng-click="start()"> {{ myText }} </button>
</body>

我的問題的第二部分是:

如何在該HTML和Angular中的代碼中應用該代碼?

HTML:

<a ng-click="Menu()" class="btn btn-default" id="menu-client">hide the search</a>

角度:

$scope.Menu = function(){
        $("#wrapper").toggleClass("toggled");
    };

更改文字:

JS

angular.module('test',[])
    .controller('MyCtrl',function ($scope) {
      $scope.myText = 'Press to start';
      $scope.start = function (myText) {
          $scope.myText = (myText === 'Starting...') ? 'Finish' : 'Starting...';
      }
});

HTML

<body ng-controller="MyCtrl">
    <button ng-click="start(myText)"> {{ myText }} </button>
</body>

改變班級:

JS

$scope.isToggled = false;

HTML

<a ng-click="isToggled = true" class="btn btn-default" ng-class="{toggled: isToggled}" id="menu-client">hide the search</a>

HTML

<a ng-click="Menu()" class="btn btn-default" id="menu-client">hide the search</a>

$scope.Menu = function(){
        $scope.isHedden = true;
   };

現在,要隱藏/顯示HTML中的哪個元素,請使用ngHide指令:

<some-element ng-hide="isHidden">Some plain text or value goes here</some-element>

請查看https://docs.angularjs.org/api/ng/directive/ngHide ,了解有關此指令的更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM