Before the problem: What we are trying to do is:
I will give a script tag and a piece of javascript to another domain. It will be kind of a widget project. When other site puts my javascript into their website, my javascript will be loaded and inject widget's html.
Widget's html is built with Angular and it's working fine when i directly call that html but it's not working when injected to another page.
Here is some code.
This is how i inject widget's html:
var widget = {
initialize : function(containerId)
{
$("#" + containerId).load("widget.html");
}
}
My widget's html
<script src="http://localhost:8000/bower_components/angular/angular.js"></script>
<script src="../Controllers/phoneController.js"></script>
<div ng-app="phonecatApp">
<ul ng-controller="PhoneListCtrl">
<li ng-repeat="phone in phones">
<span>{{phone.name}}</span>
<p>{{phone.snippet}}</p>
{{2+2}}
</li>
</ul>
</div>
</div>
Aand my controller:
var phonecatApp = angular.module('phonecatApp', []);
phonecatApp.controller('PhoneListCtrl', function ($scope) {
$scope.phones = [
{'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'},
{'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'},
{'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.'}
];
});
The exception in the console:
Uncaught Error: [$injector:modulerr] Failed to instantiate module phonecatApp due to: Error: [$injector:nomod] Module 'phonecatApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
Edit: There is {{2+2}} code in my html, just to test Angular. It's not evaluated by Angular and printed into html as it is.
phoneController.jsis correct? Since you are using a relative path it might not be pointing to where you think. - Patrick Evansng-appis attempting to boot the app before your phoneController.js code has been loaded. (Normally that would wait for domready, but that's likely already happened). - Hargo