I am using angular js, and want to define actions on a button that presents a loading spinner, then loads some content. I am trying to make correct separation between view and controller, but I can't think how to do it properly.
Currently, I am setting a variable in the controller, and watching it in the view - but it seems a bit long winded.
HTML
<div ng-app="myApp">
<div ng-controller="inControl">
<button ng-click="doIt()">Cool <i ng-show="loading">...</i></button>
</div>
</div>
JS
var app = angular.module('myApp', []);
function inControl($scope) {
$scope.loading = false
$scope.doIt = function(){
$scope.loading = true
setTimeout(function(){
$scope.loading = false
$scope.$apply()
}, 500)
};
}
Fiddle: http://jsfiddle.net/billymoon/4es3h/
What is the proper way to handle this scenario using angular js?