简体   繁体   中英

Firefox extension implementing AngularJS

I am trying to use "self.port.emit" in my angular service to send my add-on a result from the UI. The problem is I am not getting any errors so, I am not sure why the panel is not detecting the self.port.

Below is my current folder structure:

add-on/
    lib/
        toolbar.js
    data/ 
        angularApp/
            app/ 
            scripts/
                controllers/
                    groupCtrl.js
                services/
                    groupservice.js

In my gorupservice.js I have the following code:

angular.module('angularApp').service('groupservice'), function() {
    this.addGroup = function(name) {
        self.port.emit("newGroupName", name);
    }
}

The groupservice is called by the groupCtrl.js. The function addGroup is being called. In toolbar.js, I have a "self.port.on" listening for the "newGroupName". In toolbar.js, I have

function createSettingsPanel() {
     var settingsPanel = require("sdk/panel").Panel({
         ...
         contentScriptFile: [data.url("angularApp/app/bower_components/angular/angular.js"),  
         data.url("angularApp/app/scripts/app.js"),
         data.url("angularApp/app/scripts/controllers/groupservice.js")],
     });

     settingsPanel.port.on("newGroupName", function() {
         console.log("MADE IT"); //NOT GETTING HERE!
     }); 
}

If anyone has any experience with angular.js in a Firefox add-on, the help would be greatly appreciated.

在内容脚本(角度应用程序)中,使用addon.port.emit代替self.port.emit即可。

It's a shot in the dark, but should this code:

angular.module('angularApp').service('groupservice', function() {
    this.addGroup = function(name) {
        self.port.on("newGroupName", name);
    }
}

be

angular.module('angularApp').factory('groupService', function() {
    var groupService;

    groupService.addGroup = function(name) {
        self.port.emit("newGroupName", name);
    }

    return groupService;
}

You looking for a singleton right?

Some questions: is "self" a global variable? Is self.port defined when you inject the service?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM