Angular element.width is not a function?

Doesn't it work element.width()

or am I wrong in assuming that it gives you the width of the element?

angular.module('app', []).directive('app', function() {
  return {
    restrict: 'E',
    link: function(scope, element) {
      console.log(element.width());
      // => Error: element.width is not a function
    },
  };
});
      

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
  <app></app>
</div>
      

Run codeHide result


+3


source to share


1 answer


from angularjs angular.element docs :

If jQuery is available, angular.element is an alias for the jQuery function. If jQuery is not available, the angular.element delegates for Angular's built-in jQuery subset, called "jQuery lite" or "jqLite".



jqlite has a limited api and it doesn't include the .width () function

+6


source







All Articles