Angular js脚本加载

时间:2016-07-25 10:54:46

标签: javascript angularjs

这是我运行角度应用的方式

<!DOCTYPE html>
<html class="no-js"  ng-app="BasicHttpAuthExample"> <!--<![endif]-->
    <head>
        <script src="<?= ASSETS_PATH ?>/js/app2.js"></script>
        <script src="<?= ASSETS_PATH ?>/js/main.js"></script>
        <script src="http://localhost/SPA_DEMO/assets/js/jquery.countTo.js"></script>
    </head>
    <body ng-app="BasicHttpAuthExample"> 
        <nav id="fh5co-main-nav" role="navigation">  
            <a href="#" class="js-fh5co-nav-toggle fh5co-nav-toggle active" id="Close"><i></i></a>
            <div class="js-fullheight fh5co-table">
                <div class="fh5co-table-cell js-fullheight">
                    <ul>
                        <li></li>
                        <li class="active"><a href="index.html">Home</a></li>
                        <li><a href="gallery.html">Gallery</a></li>
                        <li><a href="services.html">Services</a></li>
                        <li><a href="about.html">About</a></li>
                        <li><a href="contact.html">Contact</a></li>
                    </ul>
                </div>
            </div>
        </nav>
    <ng-view>
    </ng-view>
</body>
</html>

在此我正在加载视图时,此文件中加载的脚本在视图中不可用。如何在每次加载视图时加载某些脚本或如何在视图中加载可用的脚本。

1 个答案:

答案 0 :(得分:0)

尝试确保在body标记附近的底部加载脚本,以便在加载dom时加载它们。还要确保首先加载Jquery和其他库之类的外部脚本,因为你的javascript文件可能依赖于它们。

您不必两次指定ng-app指令。它在身体标签上没问题。 你也错过了一个控制器指令。

 <html class="no-js" > <!--<![endif]-->
    <head>

    </head>
    <body ng-app="BasicHttpAuthExample" ng-controller="//your controller"> 
        <nav id="fh5co-main-nav" role="navigation" >  
            <a href="#" class="js-fh5co-nav-toggle fh5co-nav-toggle active" id="Close"><i></i></a>
            <div class="js-fullheight fh5co-table">
                <div class="fh5co-table-cell js-fullheight">
                    <ul>
                        <li></li>
                        <li class="active"><a href="index.html">Home</a></li>
                        <li><a href="gallery.html">Gallery</a></li>
                        <li><a href="services.html">Services</a></li>
                        <li><a href="about.html">About</a></li>
                        <li><a href="contact.html">Contact</a></li>
                    </ul>
                </div>
            </div>
        </nav>

    <ng-view>
    </ng-view>
        <script src="http://localhost/SPA_DEMO/assets/js/jquery.countTo.js"></script>
        <script src="<?= ASSETS_PATH ?>/js/app2.js"></script>
        <script src="<?= ASSETS_PATH ?>/js/main.js"></script>

</body>
</html>