0

I have implemented a code to show a busy icon and this is it

angular.module("app", [])

    .controller('UploadCtrl', function ctrl ($scope, $timeout) {
        $scope.busy = false;

        $scope.submit = function () {
            $scope.busy = true;

            // pretend to make an http call...
            $timeout(function () {
                $scope.busy = false;
            }, 10000);
        };
    });

This is the index.html file

<!DOCTYPE html>
<html>
<head>
    <link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
    <script src="app.js"></script>
    <meta charset="utf-8">
    <title>Busy Runner</title>
</head>
<body ng-app="app" ng-controller="ctrl">
    <button ng-disabled="busy" ng-click="submit()">Submit <i class="fa fa-spinner fa-spin" ng-show="busy"></i></button>
</body>
</html>

When I run the code the busy loader keeps running. Please what could be wrong. This is the plunk I have made. view plunk

6
  • 2
    What's wrong? The spinner stops after 10 seconds as designed. Commented Oct 13, 2015 at 11:18
  • I want is triggered on button click. That was my motive. Commented Oct 13, 2015 at 11:19
  • 1
    Maybe you should tell us what you try to do. It starts the spinner when you click the button. What do you expect? Commented Oct 13, 2015 at 11:20
  • Take a look: plnkr.co/edit/qkSUDrA6jP4Y0nKvexe6?p=preview Commented Oct 13, 2015 at 11:23
  • Also take a look: plnkr.co/edit/qkSUDrA6jP4Y0nKvexe6?p=preview. This is achieved embedding it in a controller. And it keeps spinning by default Commented Oct 13, 2015 at 11:24

2 Answers 2

1

You reference a controller which not exists. Fix the HTML code

<body ng-app="app" ng-controller="UploadCtrl">
Sign up to request clarification or add additional context in comments.

Comments

1
angular.module("app", [])

    .controller('UploadCtrl', function ctrl ($scope, $timeout) {
        $scope.busy = false;

In the above code you have name your controller as 'UploadCtrl' ,where as, in HTML file

<body ng-app="app" ng-controller="ctrl">

controller is 'ctrl' , due to which it can't load the controller hence the angular part is not executed.

Change your app.js to

angular.module("app", [])
    .controller('ctrl', function ($scope, $timeout) {..}

View plunkr

Also I removed ng-disabled from <button ng-disabled="busy" ng-click="submit()">Submit since you are already using $scope.busy = false; as soon as script loads.

Checkout ngController .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.