我正在使用angularjs应用,并且要根据ng-repeat的条件更改按钮的文本。

代码是:

    <button class="save btn btn-inverse" data-ember-action="3432" style="margin-left: 380px"
        type="submit" ng-disabled="editForm.$invalid || isSaving">
            Submit as <strong>{{vm.buttonText}}</strong>
    </button>

    <button class="btn btn-inverse dropdown-toggle" data-toggle="dropdown" ng-click="showDetails = ! showDetails">
            <span class="caret"></span>
    </button>

    <ul id="ember3445" class="ember-view menu dropdown-menu pull-right" ng-show="showDetails">
        <li id="status.id" class="ember-view open status _tooltip" ng-repeat="status in vm.ticketStatus" >
                <a href="">Submit as <strong>{{status.status}}</strong></a>
        </li>
    </ul>


控制器部分:

    vm.ticketStatus = [];
    vm.ticketStatus.push({id: 'ember3451', status: 'New'},
            {id: 'ember3452', status: 'Open'},
            {id: 'ember3453', status: 'Pending'},
            {id: 'ember3454', status: 'On hold'},
            {id: 'ember3455', status: 'Solved'});

    vm.buttonText;
    vm.changeStatus = function (status){
        console.log("dsfdsfd");
        if(status != null){
            if(status == 'New'){
                vm.buttonText = 'New';
            } else if(status == 'Open'){
                vm.buttonText = 'Open';
            } else if(status == 'Pending'){
                vm.buttonText = 'Pending';
            } else if(status == 'On hold'){
                vm.buttonText = 'On hold';
            } else if(status == 'Solved'){
                vm.buttonText = 'Solved';
            } else {
                vm.buttonText = 'New';
            }
            return "" + vm.status;
        } else{
            return 'New';
        }
    };


我试图做这样的事情,但没有奏效。我想要的是当我将ng-repeat条件选择为“未决”时(例如),按钮的文本应更改为“提交为未决”。

感谢您提供各种帮助,在此先感谢...

最佳答案

没有显式调用change函数。

解决的柱塞:https://plnkr.co/edit/gWhfUCCh1doYVp0vzown

HTML:

 <div ng-controller="Ctrl">
  <button class="save btn btn-inverse" data-ember-action="3432" style="margin-left: 380px" type="submit">
        Submit as         <strong>{{vm.buttonText}}</strong>
  </button>
  <ul>
    <li id="status.id" class="ember-view open status _tooltip" ng-repeat="status in vm.ticketStatus">
      <a href="" ng-click="vm.changeStatus(status.status)">Submit as             <strong>{{status.status}}</strong>
      </a>
    </li>
  </ul>
</div>


控制器:

function Ctrl($scope) {
 $scope.vm = {};
 $scope.vm.ticketStatus = [];
 $scope.vm.ticketStatus.push({id: 'ember3451', status: 'New'},
           {id: 'ember3452', status: 'Open'},
            {id: 'ember3453', status: 'Pending'},
            {id: 'ember3454', status: 'On hold'},
            {id: 'ember3455', status: 'Solved'});

 $scope.vm.buttonText;
 $scope.vm.changeStatus = function (status){
        console.log("dsfdsfd");
        if(status !== null){
            if(status == 'New'){
               $scope.vm.buttonText = 'New';
            } else if(status == 'Open'){
               $scope.vm.buttonText = 'Open';
            } else if(status == 'Pending'){
                $scope.vm.buttonText = 'Pending';
            } else if(status == 'On hold'){
                $scope.vm.buttonText = 'On hold';
            } else if(status == 'Solved'){
                $scope.vm.buttonText = 'Solved';
            } else {
               $scope.vm.buttonText = 'New';
            }
            return "" + vm.status;
        } else{
            return 'New';
        }
    };
}

关于javascript - AngularJs-要在ng-repeat的基础上更改按钮的文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37179241/

10-09 22:20