Ng-view没有加载模板(没有web服务器运行)

ng-view not loading the template (no web server running)

本文关键字:web 没有 服务器 运行 加载 Ng-view      更新时间:2023-09-26

类似问题的答案我都试过了,都没有成功。我有一个像这样的项目目录结构:

  • 应用

    config.js

    • 共享

      Layout.html

    • 国内

      index . html

这里的config.js, Shared和Home在同一个级别。

My Layout.html的代码是:

    <!DOCTYPE html>
    <html ng-app="app">
    <head>
    <script type="text/javascript" src="../Assets/ng/angular/angular.js"></script>
    <script type="text/javascript" src="../Assets/ng/angular-route.js"></script>
    <script type="text/javascript" src="../config.js"></script>
    </head>
    <body>
         <a href="#/">Home</a>
         <section ng-view></section>
    </body>
    </html>

My Index.html只有"Home view"字样。

config.js文件:

angular.module("app", ['ngRoute')
.config(['$routeProvider', function($routeProvider){
    $routeProvider
    .when('/', {
        templateUrl: '../Home/Index.html'
    })
    .otherwise({
        redirecTo: '/'
    });
}]);

然而,这在<section></section>中没有显示任何内容。不会抛出异常。顺便说一句,我没有运行web服务器。我只是在Chrome中打开我的Layout.html,然后点击链接,但模板没有加载。

当页面在Chrome中打开时,浏览器中的url类似于

file:///Users/user.name/Desktop/folder1/subfolder1/app/Shared/Layout.html#/

我的方法有什么问题?谢谢。

兄弟,请使用本地服务器加载应用程序。要么用visual studio,要么如果你懂nodejs就用它。