Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs templates in chrome extension

I am running into a strange issue while using angularjs template in a content script based chrome extension. I go in an infinite loop. When I use an inline template (using template attribute with a string), it works fine. Can anybody suggest what I am doing wrong?

manifest.json

{
  "name": "Content Script Cross-Domain XMLHttpRequest Example",
  "version": "2.0.0",
  "manifest_version": 2,
  "description": "Demonstrates making cross domain requests from a content script by putting Twitter trends on Google News.",
  "permissions": [
    "http://localhost:9393/*"
  ],
  "icons": {
    "48" : "sample-48.png",
    "128" : "sample-128.png"
  },
  "content_scripts": [
    {
      "matches": ["http://news.google.com/*","*://mail.google.com/*"], 
      "js" : ["lib/jquery-1.6.4.min.js","lib/angular-1.0.1.min.js", "app.js","contentscript.js"]
    }
  ]
}

app.js

angular.module('myApp', []).
  config(['$routeProvider', function($routeProvider) {
  console.log('inside angular.module');
  $routeProvider.
      when('/', {templateUrl: 'contact.html',   controller: AppController}).
      otherwise({redirectTo: '/'});
}]);


function AppController($scope){
  console.log('inside AppController');
}

inside contentscript.js

$(this).append('<div id="gmeAppContainer">'
                                 + '<div ng-view></div>'
                              + '</div>');
var rootEle = $(this).find('#gmeAppContainer');
angular.bootstrap(rootEle,['myApp']);

When I use inline tempate in app.js,it works fine.

when('/', {template: '<div>This is inline template </div>',   controller: AppController}).

Have also posted on angularjs google group https://groups.google.com/d/topic/angular/A_SVYZWPKe8/discussion

like image 554
user1566788 Avatar asked Oct 07 '22 01:10

user1566788


1 Answers

It looks like I figured it out.

First declare the template file in manifest.json file.

  "web_accessible_resources" :[
      "contact.html"
  ]

Then use the chrome.extension.getURL method to get the absolute url to the template file

  when('/', { controller: AppController, templateUrl : chrome.extension.getURL('contact.html')}).
like image 121
user1566788 Avatar answered Oct 09 '22 14:10

user1566788