如何在html中以角度显示自定义指令的作用域

How to display the scope in html from a custom directive in angular?

本文关键字:自定义 显示 指令 作用域 html      更新时间:2023-09-26

我是angular js的新手。

如何在HTML中显示e.widthe.height的值?我可以用一下这里的示波器吗?

    .directive( "cropping", [function ($scope) {
  return {
      restrict: "A",
      link    : function ( $scope, $el, $attr ) {
          $attr.$observe( "src", function ( src ) {
                      jQuery( '#cropImage' ).cropper('destroy');
                      jQuery( '#cropImage' ).cropper( {
                          viewMode        : 0,
                          zoomable        : false,
                          preview: ".extra-preview",
                          dragMode        : 'crop',
                          guides          : true,
                          highlight       : true,
                          cropBoxMovable  : true,
                          cropBoxResizable: true,
                          crop            : function ( e ) {
                              // Output the result data for cropping image.
                              console.log( e.width );
                              console.log( e.height );
                          }
                      } );
          } );
      }
  }
} ] );

使用下面的代码,您将直接获得HTML的高度和宽度。

console.log( e[0].offsetHeight);
console.log( e[0].offsetWidth);