错误AngularJS指令追加下页 [英] Error appending Pagedown in AngularJS Directive

查看:159
本文介绍了错误AngularJS指令追加下页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,虽然我觉得这保证了自己的问题:谷歌PageDown键AngularJS指令

Based on this question, though I felt this warranted its own question: Google pagedown AngularJS directive

继这个问题的例子,似乎工作,但我遇到问题时,我尝试将指令追加到该页面。

Following the example from this question, it seems to work, however I am running into issues when I try to append a directive to the page.

下面是code我在链接功能:

Here is the code I have in the linking function:

  scope.editor_id = null;

  if(attrs.id == null) {
    scope.editor_id = nextID++;
  } else {
    scope.editor_id = attrs.id;
  }

  //append editor HTML
  //has to be done here so that it is available to the editor when it is run below
  var editor_html = $compile(
      '<div id="wmd-button-bar-' + scope.editor_id + '"></div>' +
      '<textarea class="wmd-input" id="wmd-input-' + scope.editor_id + '" ng-model="content"></textarea>'
  )(scope);


  element.find('.wmd-panel').append(editor_html);


  var editor = new Markdown.Editor(editor_converter, "-" + scope.editor_id);
  editor.run();

但是,当我追加的这一个文件,我得到以下错误:

However, when I append one of these to the document, I get the following error:

TypeError: Cannot read property 'attachEvent' of null

此错误往往会突然出现在大规模杀伤性武器输入不在HTML present。但是,我与 $编译函数添加它,和它的作品在页面加载,而不是当它被追加。我在做什么错在这里?

This error tends to crop up when the wmd-input is not present in the HTML. however, I am adding it with the $compile function, and it works on page load, but not when it is appended. What am I doing wrong here?

推荐答案

我能够重现你的问题: http://plnkr.co/edit / R2eDKBreHmYBjPtU0JxD?p = preVIEW

UPDATE

I was able to reproduce your problem: http://plnkr.co/edit/R2eDKBreHmYBjPtU0JxD?p=preview


  • 我错了我的previous假设(复合链接功能做返回元素)

  • 问题是你用 angular.element#找到的方式。

  • angular.element#找到只搜索子元素而不是整个文件。

  • .wmd面板类的DOM元素不是当前元素的孩子。

  • I was wrong with my previous assumption ( the composite linking function do returns the element)
  • The problem is with the way you use angular.element#find.
  • angular.element#find only search for child elements not on the whole document.
  • the DOM element with a .wmd-panel class is not a child of the current element.
angular.element('.wmd-panel').append(editor_html);

这篇关于错误AngularJS指令追加下页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆