0

I have a main page with this structure.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>..:: Test Application ::..</title>
        <link rel="stylesheet" href="../bootstrap/css/bootstrap.css" />
        <link rel="stylesheet" href="../css/main.css" />
        <script src="../js/jquery.js"></script>
        <script src="../bootstrap/js/bootstrap.min.js"></script>

        <script>

          function loadOption(idopt){
              if(idopt==1){
                 var curl = '../view/otherpage.php'
              }
              $("#mainContainer").load(curl);
          }        

        </script>

     <body onLoad=loadOption(<?php echo idopt;?>)>
       <div id="mainContainer"></div>
     </body>

</html>

otherpage.php

<!DOCTYPE html>
<html ng-app>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="../js/angular.min.js"></script>
    </head>
    <body>
        {{1+1}}
    </body>
</html>

But, when i load the main page... the AngularJS doesn't run. What could be wrong?

Jhonatan Sandoval
  • 1,283
  • 6
  • 24
  • 40

3 Answers3

2

That's because you're loading otherpage.php after the DOMContentLoaded event has finished.

In other words, you're filling in the space inside the mainContainer div with otherpage.php content after the event DOMContentLoaded. And that is where Angular's Automatic Initialization takes place.

So in order to get it to work, you'll have to manually bootstrap Angular.

Here's Angular's documentation about it:

http://docs.angularjs.org/guide/bootstrap

Other options are available and are much better, such as referencing your Angular related files (angular, your controllers, services, directives and what not) at the main page.

0

Depending on the browser, pulling the script element in otherpage.php out of the head element and into the body element, should correct this.

We can't see all your code, but it may be better to just load Angular.js in the head of the main page. You could do this using your own a script package manager control flow to avoid this type of failure for other dependencies. That would be good style...

taddy hoops
  • 593
  • 2
  • 16
0

make a common includes page and add angular.js file to it and include it in the header so that it is available through out the site or use it in the main page

vnimbala
  • 74
  • 5