1

I have a website full of exercises. I'm using jQuery load() to load parts of pages when a link on my website is clicked.

This takes the relevant part of the wanted page (the exercise itself) and puts it in a div for the user to interact with. While this works wonderfully for most of the website, since the vast majority is written in php, I'm trying to get it to work with the parts that use AngularJS as well.

I used this question as a starting point: AngularJS + JQuery : How to get dynamic content working in angularjs

It worked fairly well but only for one exercise. I think that manually bootstrapping angularJS could fix my problem but so far have had issues. How can I manually bootstrap my angular app upon jQuery load?

Here's some of what I've tried so far but it doesn't work:

irscript.js (ir is the name of the exercise) relevant code:

var ir = angular.module("ir", []);
ir.controller('MainCtrl', function($scope) {
//application logic.
});
angular.element(document).ready(function() {
angular.bootstrap(document, ['ir']);
});

index.html relavent code:

<script>
 $("#content").load(String(url + " #exercise"), function(){
 $.getScript("irscript.js")});

</script>
<div id="content"></div>

The hope is that irscript.js can be replaced by a function that returns the proper script for the loaded exercise at some point but just getting the above to work would be amazing.

Community
  • 1
  • 1
L1313
  • 11
  • 5
  • Did you include `angular.js`? Did you remove the `ng-app` directive from your template? – georgeawg Nov 17 '15 at 07:00
  • You can describe in what way it isn't working? Try based on this: http://plnkr.co/edit/vQ9tTCrrBqDhbBoMBi6l?p=preview – tasseKATT Nov 17 '15 at 11:50
  • Thanks for for the Plunker. The issue is that load() loads the angular page I want, and then the callback is supposed to load the script and bootstrap the angular elements in the loaded div so that I get a nice, functioning, angularJS web page. However, since load() doesn't happen till the link is clicked, I don't want to load the angularJS script until the page I'm loading it for is asked for. – L1313 Nov 17 '15 at 16:52

0 Answers0