angularjs templates inside chrome extension

477 views
Skip to first unread message

spdev

unread,
Jul 31, 2012, 1:19:31 AM7/31/12
to ang...@googlegroups.com
I am running into a strange issue while using angularjs template in a content script within a 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 file-----------------------------------------------
{
  "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": [
  ],
  "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');
}


--------------------------------------content script--------------------------------

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



spdev

unread,
Aug 1, 2012, 2:12:28 AM8/1/12
to ang...@googlegroups.com
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')}).
Reply all
Reply to author
Forward
0 new messages