0

我正在尝试更改按钮图标 thext 并希望禁用 onClick()。

不幸的是,当我第一次单击时它会更改文本,当我再次单击时它会更改图标但不会禁用它。

在堆栈中,变量在单击事件后正确设置。我真的不知道为什么它不起作用以及为什么当我单击两次时它会改变。

这是我的html:

<ion-view title="Who-U">
    <ion-content class="padding">

        <a class="item item-thumbnail-left" href="#">
            <img src="img/cover.png">
            <h2>{{username}}</h2>
            <p>Points: {{points}}</p>
        </a>

        <button ng-click="click()" class="button button-full button-positive" ng-disabled="{{buttonDisable}}">
            <i class='{{buttonType}}'></i>{{text}}
        </button>
    </ion-content>
</ion-view>

那是我的控制器:

angular.module('home', ['services'])

.controller('homeCtrl',
    function ($scope, $location, $state, localStorageService, serverAPI, $ionicPopup) {

       $scope.buttonType = "icon ion-search",
        $scope.buttonDisable = false,
        $scope.text = 'Search',


        $scope.click = function () {
            $scope.buttonDisable = true
            $scope.text = 'Searching'
            $scope.buttonType = "icon ion-loading-a"

        };

    })
4

1 回答 1

2

你忘了放';' 在您的代码中:p

尝试这个 :

   $scope.buttonType = "icon ion-search";
    $scope.buttonDisable = false;
    $scope.text = 'Search';


    $scope.click = function () {
        $scope.buttonDisable = true;
        $scope.text = 'Searching';
        $scope.buttonType = "icon ion-loading-a";
}
于 2015-05-04T12:33:00.190 回答