0

How can I fix this error?

TypeError: object is not a function
    at http://localhost:9000/app/topItems/topItems.directive.js:30:11
    at Scope.$broadcast (http://localhost:9000/bower_components/angular/angular.js:12887:28)
    at Scope.$destroy (http://localhost:9000/bower_components/angular/angular.js:12545:14)
    at Scope.$delegate.__proto__.$destroy (<anonymous>:812:29)
    at cleanupLastView (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2712:26)
    at http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2739:13
    at publicLinkFn (http://localhost:9000/bower_components/angular/angular.js:5933:29)
    at updateView (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2733:23)
    at http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:2697:11
    at Scope.$broadcast (http://localhost:9000/bower_components/angular/angular.js:12887:28) angular.js:9997

Here is the directive at fault:

.directive('topItems', ['$window', function($window) {
    var linkFn;
    linkFn = function(scope,element,atts) {
      function setHeight() {
        var winHeight = $(window).height();
        var headerHeight = 72;
        var topItemHeight = winHeight - headerHeight + 'px';
        element.css('height', topItemHeight);

        if(winHeight < 480)
          scope.limit = 6; // 
        else if(winHeight > 480 && winHeight < 600)
            scope.limit = 9;
        else if(winHeight > 600 && winHeight < 850)
            scope.limit = 12;
        else if(winHeight > 850)
            scope.limit = 18;

        // console.log(winHeight, headerHeight, topItemHeight, scope.limit);
      }

      setHeight();

      var windowListenerDeregistraion = $(window).on('resize', setHeight);

      // I think the problem is to do with the $destroy
      scope.$on('$destroy', function(){
          windowListenerDeregistraion();
      });
    }
    return {
      restrict: 'E', // Restrict to E(Element), A(Attribute)
      // scope: {
      //   limit: '@'
      // },
      templateUrl: 'app/topItems/topItems.html',
      link: linkFn
    }
  }]);
0

1 Answer 1

1

windowListenerDeregistraion is a jQuery object, not a function.

You have already bound a handler to the window resize event as soon as you exposed $(window).on('resize', setHeight);.

You shouldn't need to do it again although it isn't clear what your expectations are.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.