1

my directive controller $scope.closeSpinner function isn't being triggered when button ng-click="closeSpinner()" is clicked on the directive template.

AddUsers.Html

<div spinner spinneron="playerSearchSpinnerOn"> </div>

Directive

monopolyMenuModule.directive('spinner', ['spinObj', function (spinObj) {
    return {

        restrict: "A",
        scope:{
            spinneron: "="
        },
        link: function ($scope, elem, attr) {
            $scope.$watch('spinneron', function (newValue, oldValue) {
                if (newValue != oldValue) {
                    if (newValue) {
                        // load spinner, create a model dialog, with a cancel button.
                        var spinner = spinObj.spin();
                        var element = angular.element(".modal-content");
                        element.append(spinner.el);
                        $("#spinnerDialog").modal('show')
                    }
                    else if (newValue == false) {
                        // close spinner called.
                        spinObj(false);
                    }
                }
            });

        },
        controller: function($scope)
        {
            $scope.closeSpinner = function () {
                $scope.spinneron = false;
            }
        },
        templateUrl: '/Js/MonopolyMenu/model.html'
    }
}]);

Template Html

<div class="modal fade" id="spinnerDialog" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-footer">
            <button class="btn btn-success" data-dismiss="modal" ng-click="closeSpinner()">Cancel</button>
        </div>
    </div>
</div>

4
  • 3
    Where are you using you directive? I don't see it anywhere. Commented Apr 18, 2015 at 18:52
  • Are there any errors in the console? Commented Apr 18, 2015 at 19:22
  • 2
    Probably the easiest way to help is if you create a Plunker or Fiddle as it isn't obvious from your samples what could be the problem. Commented Apr 18, 2015 at 19:27
  • Plunker: plnkr.co/edit/GQAm8x?p=info Commented Apr 18, 2015 at 19:41

1 Answer 1

2

Based on the provided Plunkr, it seems to be working just fine. You should make sure your file paths are setup correctly to the template within the directive. Perform a test that it is being called with a console.log or $log.log call (as I have done in the plunk). Also, feel free to add the spinObject code to the provided Plunk.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeh, it works on mine also. I just had to clear the cache, and viola.. sorry for the post.

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.