首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >instance.rootElement.getAttribute不是一个函数

instance.rootElement.getAttribute不是一个函数
EN

Stack Overflow用户
提问于 2018-01-02 14:44:25
回答 1查看 343关注 0票数 1

我正在尝试在应用程序中使用handsontable,并用代码做了一些实验。我现在面临错误--“instance.rootElement.getAttribute不是一个函数”。当我检查它发生在代码行时

hot =新的Handsontable(容器,{

我的index.html

代码语言:javascript
复制
<!DOCTYPE html>
<html ng-app="myApp">
<head>

<script type="text/javascript" src="https://docs.handsontable.com/0.16.1/scripts/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js"></script>
<script type="text/javascript"src="https://docs.handsontable.com/0.16.1/bower_components/handsontable/dist/handsontable.full.js"></script>
<script type="text/javascript" src="js/dragresize.js"></script>
<link type="text/css" rel="stylesheet" href="https://docs.handsontable.com/0.16.1/bower_components/handsontable/dist/handsontable.full.min.css">
</head>

<body >

<div id="example1" class="hot handsontable htRowHeaders htColumnHeaders" data-drag-resize></div>
</body>

</html>

我的dragresize.js

代码语言:javascript
复制
angular.module('myApp',[]).directive('dragResize',function(){
    return{
        restrict: 'AEC',
        replace:true,
        controller: function($scope, $timeout){
            //document.addEventListener("DOMContentLoaded", function() {

  var container = angular.element(document.getElementById('example1')),
    hot;

  hot = new Handsontable(container, {
    data: Handsontable.helper.createSpreadsheetData(200, 10),
    rowHeaders: true,
    colHeaders: true,
    colWidths: [55, 80, 80, 80, 80, 80, 80],
    rowHeights: [50, 40, 100],
    manualColumnResize: true,
    manualRowResize: true
  });

  function bindDumpButton() {
      if (typeof Handsontable === "undefined") {
        return;
      }

      Handsontable.Dom.addEvent(document.body, 'click', function (e) {

        var element = e.target || e.srcElement;

        if (element.nodeName == "BUTTON" && element.name == 'dump') {
          var name = element.getAttribute('data-dump');
          var instance = element.getAttribute('data-instance');
          var hot = window[instance];
          console.log('data of ' + name, hot.getData());
        }
      });
    }
  bindDumpButton();
    $timeout(dragResize,0);
//});
        }

    };
});

/* document.addEventListener("DOMContentLoaded", function() {

  var
    container = document.getElementById('example1'),
    hot;

  hot = new Handsontable(container, {
    data: Handsontable.helper.createSpreadsheetData(200, 10),
    rowHeaders: true,
    colHeaders: true,
    colWidths: [55, 80, 80, 80, 80, 80, 80],
    rowHeights: [50, 40, 100],
    manualColumnResize: true,
    manualRowResize: true
  });

  function bindDumpButton() {
      if (typeof Handsontable === "undefined") {
        return;
      }

      Handsontable.Dom.addEvent(document.body, 'click', function (e) {

        var element = e.target || e.srcElement;

        if (element.nodeName == "BUTTON" && element.name == 'dump') {
          var name = element.getAttribute('data-dump');
          var instance = element.getAttribute('data-instance');
          var hot = window[instance];
          console.log('data of ' + name, hot.getData());
        }
      });
    }
  bindDumpButton();
$timeout(container,0);
}); */

我不确定这个错误到底是什么意思。我正在尝试将现有的javascript文件集成到我的angularjs文件中。如有任何信息/帮助,我们将不胜感激

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-02 15:05:00

替换

代码语言:javascript
复制
container = angular.element(document.getElementById('example1'))

代码语言:javascript
复制
container = $document[0].getElementById('example1')

并将$document添加到函数参数中,如下所示

代码语言:javascript
复制
directive('dragResize', function($document) { ... }

希望这能有所帮助。

请向我询问更多问题。

谢谢。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48056643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档