2017-05-19 80 views
0

我需要改變按鈕文本與NG單擊功能字體真棒微調。如何更改按鈕文本在微調NG單擊

<input id="Button1" type="button" value="{{buttonText}}" ng-click="Save()" /> 

我的劇本爲

app.controller("CateCtrl", function ($scope, $http) { 
    $scope.buttonText = 'Save'; 
    $scope.Save = function() { 
      $scope.buttonText = '<i class="fa fa-spinner fa-pulse"></i> Please wait'; 
     }); 
    }); 

它更改文本,因爲它是'請等待

不顯示微調icon.`

回答

0

你不能使用類的按鈕名稱,你正在做這將您的按鈕更改名稱<i class="fa fa-spinner fa-pulse"></i> Please wait方式,使用ng-class,並試圖改變它的圖標。

1

使用納克級

<button><i ng-class="{'fa fa-spinner fa-pulse' : loading}"></i></button> 

在按鈕的點擊設置

app.controller("CateCtrl", function ($scope, $http) { 
     $scope.buttonText = 'Save'; 
     $scope.Save = function() { 
      $scope.loading = true; 
     }); 
    }); 

EDIT1:你可以有你的按鈕標籤內的HTML。 Read

0

這裏是解決方案,使用ng-if條件。

<!DOCTYPE html> 
 
<html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> 
 
<body> 
 

 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
<button> 
 
    <i ng-click="Save()" ng-if="loading" class="fa fa-spinner fa-pulse"></i> 
 
    <span ng-click="Save()" ng-if="!loading">Save</span> 
 
</button> 
 

 
</div> 
 

 
<script> 
 
var app = angular.module('myApp', []); 
 
app.controller('myCtrl', function($scope) { 
 
    
 
     $scope.Save = function() { 
 
      $scope.loading = !$scope.loading; 
 
     }; 
 
    
 
}); 
 
</script> 
 

 
</body> 
 
</html>

Here is a working DEMO

相關問題