Reputation: 65
I need to to change button text with font awesome spinner on ng-click function.
<input id="Button1" type="button" value="{{buttonText}}" ng-click="Save()" />
My Script as
app.controller("CateCtrl", function ($scope, $http) {
$scope.buttonText = 'Save';
$scope.Save = function () {
$scope.buttonText = '<i class="fa fa-spinner fa-pulse"></i> Please wait';
});
});
It change the text as it is ` Please wait
Not showing spinner icon.`
Upvotes: 0
Views: 2096
Reputation: 18647
Here is the solution, using ng-if
condition.
<!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>
Upvotes: 1
Reputation: 838
use ng-class
<button><i ng-class="{'fa fa-spinner fa-pulse' : loading}"></i></button>
On the click of the button set
app.controller("CateCtrl", function ($scope, $http) {
$scope.buttonText = 'Save';
$scope.Save = function () {
$scope.loading = true;
});
});
Edit1: You can have html inside your button tag. Read
Upvotes: 1