AngularJS Firebreath Component

Trying to integrate a FireBreath plugin object into an AngularJS view is causing an error when attempting to render the view:

TypeError: Cannot read property 'nodeName' of undefined

The object can be successfully included in the view using $compile as follows:

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

However, after including the object this way, triggering an event in the JavaScript code becomes problematic.

For instance:

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

Results in a

TypeError

Error in the Chrome console. But calling:

plugin.callFunction();

Executes a FireBreath method. The challenge arises when attempting to trigger an event in the JS without success. Therefore, the following code never executes:

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();

Is there an issue with accessing the object after invoking $compile? Notably, logging the plugin in regular HTML (pre-AngularJS use) returns:

<JSAPI-Auto Javascript Object> 

Suggesting that what is obtained from document.getElementById post-$compile may not be the same.

It would be more convenient if the <object> tag could be directly placed in the view.html file to display within <body class='ng-view'>. However, the initial TypeError prevents this. Suggestions for resolving this issue are highly welcome.

Any assistance is valued. Thank you.

Answer №1

If you're curious, I had trouble getting the event to trigger, so I followed the instructions provided in this link:

(I believe it's your blog @taxilian) for retrieving data back to the JS.

Plugin Code: The link provides an excellent example.

JS Code:

//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);

This solution will suffice until we can find a way to attach an event to the plugin object after $compile.

Answer №2

Encountering the same issue, I managed to resolve it by implementing a read-only nodeName property within my plugin object. Seeking advice, I posted about it in a firebreath discussion thread, where taxilian recommended adding this feature to JSAPIAuto.cpp. Following their suggestion proved effective, so I submitted a pull request with the required modifications.

Answer №3

After spending a solid 6 hours attempting to integrate FireBreath plugins with jQuery, I can confidently say that it was a valuable learning experience. However, in the end, I came to the realization that the effort required wasn't justified.

To put it simply, the compatibility issues make it not worthwhile. Even if you manage to get it functioning, there are problems with IE9 where FireBreath doesn't support addEventListener (IE fails to provide event information), making support challenging and forcing the use of attachEvent instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Integrating node.js into my HTML page

Forgive me for sounding like a newbie, but is there a simple way to integrate node.js into my HTML or perhaps include a Google API library? For example: <script>google.load(xxxx)</script> **or** <script src="xxxx"></script> ...

Using Ajax and PHP to store multiple checkbox selections into the database

I currently have 32 checkboxes on my page that I need to track the checked status for. In my JavaScript, I am looping through each checkbox and assigning a value of '1' for checked and '0' for unchecked. // Example for one checkbox if ...

Encountering an Uncaught ReferenceError in AngularJS & Jasmine/Karma: require not defined

Recently, I've been delving into the world of testing my angular app with Jasmine-Karma. As someone who is a complete novice when it comes to testing, consoles, and npm, I'd really appreciate a simple explanation (and maybe some guidance) on what ...

Unexpected object returned by the spread operator

Currently, I am utilizing node and specifically using babel-node. "start": "nodemon --exec babel-node --presets es2015 index.js" However, I have encountered an issue with my spread syntax in the following code snippet: export const login = async (parent ...

Spring Security does not support PUT requests with AngularJS and Spring Boot

Creating an Angular controller function $scope.updatePatient = function() { var patient = new patientUpdateService({id:"15", name:"m",lastname:"s"}); patient.$update(); } Defining an Angular service .factory("patientUpdateServic ...

Utilizing JQuery's printThis Plugin in Combination with the Style Attribute

I am currently working on a JavaScript app and I am trying to implement a button that will allow users to print a specific div. To achieve this, I am utilizing a jQuery plugin called printThis (github link) as well as attempting to use window.print(). $(" ...

How can I achieve auto-refresh functionality in SQLite using PHP and JavaScript without refreshing the entire page

I am currently working with a straightforward php code that retrieves data from a SQLite database by using the query "$query ="Select A from B"". The process works smoothly, and upon updating the SQLite database, I can refresh the page to display the new d ...

Creating a new route in a Express JS server to specifically handle POST requests

Just starting to learn the ropes of Javascript, and I'm diving into express to create an application that will enable users to craft new recipes, explore existing ones, and view details about each recipe. To get things moving, I've launched my s ...

The CORS policy specified in next.config.js does not appear to be taking effect for the API request

I am currently working on a Next.js application with the following structure: . ├── next.config.js └── src / └── app/ ├── page.tsx └── getYoutubeTranscript/ └── getYoutubeTranscript.tsx T ...

How do I connect to a SOAP WebService in Node.js?

I am embarking on my first journey into accessing a Web Service. Specifically, I am attempting to connect to the Banxico SOAP Webservice in order to retrieve the exchange rate of the peso (M.N.) to the dollar. I am using Node with Express and have been re ...

Avoid HTML code injection in an ExtJS4 grid by properly escaping the href attribute

I am facing an issue with escaping HTML in my Extjs grid. I have used the following configuration : return Ext.String.htmlEncode(value); In the renderer of my column, this method works perfectly for simple HTML tags like h1, b, i, etc. However, if I in ...

Optimal method to refresh v-for when updating route in Vue.js seamlessly without having to manually reload the page

What is the best approach to re-render a v-for loop in my Vue.js application when switching to another route? In my scenario, I am using Vuex, vuex-persistedstate, and moment for saving data in localStorage and displaying timestamps like "a moment ago". ...

Ember Gain a comprehensive understanding of the flow of execution between route and controller

Below is a snippet of my "box" route/controller: export default Ember.Controller.extend({ initialized: false, type: 'P', status: 'done', layouts: null, toggleFltr: null, gridVals: Ember.computed.alias('mode ...

Activate the extended view of a Material-UI Accordion

When using Accordions to display editable entities, we often want to keep modified entities in the expanded state. Currently, we have had to duplicate functionality by lifting up the expanded state into the accordion wrapper to prevent any controlled <- ...

Setting up of imagemagick node module using linuxbrew

Having trouble installing imagemagick-native as it's showing an error. Tried using the following command to install: npm install imagemaick-native --save > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c45414d ...

Tips for adjusting the horizontal position of a grid item within a map() loop

I am trying to align the text in my Timeline component from Material Ui always towards the center of the timeline. The TimelineContent contains Paper, Typography (for title and description), and an image. Currently, I have multiple TimelineContent element ...

Executing a JavaScript function when a column in a Fusion Chart is clicked

I have two div elements in HTML and I would like to have div2 load when div1 is clicked. Additionally, whenever div2 loads, a back button should also appear to return to div1. Is there a way to achieve this using HTML? <td background="images/bgTd.gif ...

How come I am able to reference a component in styled-components while others cannot?

When using styled-components, you can reference another React component using the syntax ${Label}. However, I have noticed that it only works with certain components and not others. Despite reading the documentation at , I encountered an issue when trying ...

"Exploring the best way to retrieve the angular filter value within a Node.js environment

Currently, I am facing an issue with accessing the value in Node.js using req.body when it is stored in ng-model. The ng-model includes an AngularJS filter, and I need to retrieve this filtered value from the input field in Node.js through req.body. Below ...

What is the mechanism behind angular2's spa routing functioning seamlessly without the need for the hash character in the url?

During my experience with the Angular2 "Tour of Heroes" tutorial, I made an interesting observation about how their single page application router functions without a trailing hash symbol (#) in the URL. This differs from the Kendo SPA router, which typica ...