I am attempting to load AngularJS to a page using jQuery. The reason for that is that I have a site that was build using jQuery but I want to take advantage of some of the amazingness of AngularJS to a particular page. So I did this.
jQuery(document).ready(function(jQ){
jQ.getScript( "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js", function( data, textStatus, jqxhr ){
var app = angular.module('app',[]).controller('pageController', function($scope) {
console.log('Hello');
$scope.data = 'success!';
});
});
});
Here is the HTML code:
<html>
..
<body>
...
<div ngApp="app">
<div ngController="pageController">
{{data}}
</div>
</div>
</body>
</html>
There are two problems.
- If I use "ng-app" instead of "ngApp", AngularJS throws an error saying
Module 'app' 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.
- I can see app and pageController are both loaded correctly, but {{data}} in html is not rendered and console.log('Hello'); didn't get executed as well.
Scratching my for hours now. Any help is appreciated.
ngApp
isn't a property Angular recognizes.. And there's a guide to manual bootstrapping your app: docs.angularjs.org/guide/bootstrap – tymeJV Feb 12 at 21:37<script src="...">
tag. Otherwise, I'm afraid AngularJS won't be bootstrapped automatically, and you would need to invoke angular.run(). Is there any particular reason to load it in this "creative" way? – macl Feb 12 at 21:39