gpt4 book ai didi

javascript - AngularJS 中的 Firebreath 对象

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:51:40 24 4
gpt4 key购买 nike

我曾尝试在 AngularJS View 中包含一个 FireBreath 插件对象,但是当我尝试渲染该 View 时出现此错误:

TypeError: Cannot read property 'nodeName' of undefined

我能够通过 $compile 成功地将对象包含在 View 中像这样:

$("body").append($compile('<object id="plugin" type="application/x-firebreathplugin" width="0" height="0></object>')($scope));

但是,在包含这样的对象之后,我无法让我的插件在 JS 中触发事件。

做这样的事情:

plugin = document.getElementById('plugin');
console.log(plugin);

返回

TypeError

在 Chrome 控制台中。但我仍然可以:

plugin.callFunction();

并执行 FireBreath 方法。问题是当我试图让一个事件在 JS 中触发时。无论我尝试什么,我都无法触发事件。所以这段代码永远不会执行:

var addEvent = function(obj, name, func) {
obj.addEventListener(name, func, false);
}

addEvent(document.getElementById('plugin'), 'firebreathEvent', function(data) {
console.log('data ' + data);
});

var plugin = document.getElementById('plugin');
plugin.functionThatTriggersFireBreathEvent();

有谁知道这是否与调用 $compile 后访问对象有关? ?我注意到在常规 HTML 中(在使用 AngularJS 之前)在控制台中记录插件返回这个:

<JSAPI-Auto Javascript Object> 

所以我想无论我用 document.getElementById 得到什么使用后 $compile不一样。

如果我可以包含 <object> 会更容易在 view.html 文件中添加标签并显示在 <body class='ng-view'> 中但我得到了顶级 TypeError,所以如果有人对此有任何想法,那将是首选。

感谢任何帮助。谢谢。

最佳答案

如果有人感兴趣,因为我无法触发事件,我点击了这个链接:

http://colonelpanic.net/2010/12/firebreath-tips-asynchronous-javascript-calls/

(我认为是您的博客@taxilian)将数据返回给 JS。

插件代码:链接中的很好的例子。

JS代码:

//attach FireBreath Object to AngularJS View
$("body").append($compile('<object id="plugin" type="application/x-firebreathplugin" width="1" height="1"><param name="onload" value="pluginLoaded"/></object>')($scope));

var callback = function(data) {
//data is an object
console.log(data.resultFromFireBreath);
}

plugin = document.getElementById("plugin");
plugin.getData(callback);

在有人弄清楚如何在 $compile 之后将事件附加到插件对象之前,这必须暂时有效。

关于javascript - AngularJS 中的 Firebreath 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15351830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com