title: How can I fix this Error in AngularJS
body: <p>How can I fix this error?</p>
  
  <pre><code>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 (&lt;anonymous&gt;: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
  </code></pre>
  
  <p>Here is the directive at fault:</p>
  
  <pre><code>.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 &lt; 480)
            scope.limit = 6; // 
          else if(winHeight &gt; 480 &amp;&amp; winHeight &lt; 600)
              scope.limit = 9;
          else if(winHeight &gt; 600 &amp;&amp; winHeight &lt; 850)
              scope.limit = 12;
          else if(winHeight &gt; 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
      }
    }]);
  </code></pre>