在视图文件夹angularjs的index.html视图、文件夹、angularjs、index

2023-09-13 03:43:54 作者:杨洋的舍友

我有一点混乱。使用的NodeJS

I have little confusion. Using Nodejs

文件夹结构图像附加。

如果我把 index.html的在客户端文件夹的根比一切工作正常。

If I put index.html at the root of Client folder than everything is working fine.

在,如果我在视图中移动的index.html另一方面夹喜欢比JS文件不加载,但index.html的加载的形象。

On the other hand if I move index.html in the views folder like in the image than js files are not loading but index.html is loading.

的NodeJS - server.js

app.configure(function () {
    app.set('port', process.env.PORT || 3000);

    app.use(express.favicon());
    app.use(express.cookieParser());
    app.use(express.bodyParser());
    app.use(express.logger('dev'));  //tiny, short, default
    app.use(express.methodOverride());
    app.use(express.cookieSession({secret: "sdfr"}));

    //app.set('views', __dirname + '/client/views/');
    app.use(express.static(__dirname + '/client/views'));

});

app.js

app.config(['$routeProvider', function ($routeProvider) {

        $routeProvider.when('/',
            {
                templateUrl: 'partials/home.html',
                controller: 'HomeCtrl'
            });
        $routeProvider.when('/login',
            {
                templateUrl: 'partials/login.html',
                controller: 'LoginCtrl'
            });
        $routeProvider.when('/register',
            {
                templateUrl: 'partials/register.html',
                controller: 'RegisterCtrl'
            });

        $routeProvider.when('/404',
            {
                templateUrl: 'partials/404.html'
            });
        $routeProvider.otherwise({redirectTo: '/404'});

        //$locationProvider.html5Mode(true);

    }])

的index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html ng-app="contactManager">
<head>
    <meta charset="utf-8">
    <title>Angular Demo</title>
</head>

<body>


<a href="#/">Home</a><br/>
<a href="#/login">Login</a><br/>
<a href="#/register">Register</a><br/>
<a href="#/private">Private</a><br/>
<a href="#/admin">Admin</a><br/>
<a href="#/404">404</a><br/>

<div>
    <div ng-view></div>
</div>

<script src="../lib/vendor/angularjs/1.1.5/angular.min.js"></script>

<script src="../js/app.js"></script>
<script src="../js/controllers.js"></script>

</body>

推荐答案

目前您还不包括JS在前press.static 。从index.html文件的 ../ JS 所包含的JS源无处可去,因为客户端/视图是唯一目录由前press.static 服务。

Currently you are NOT including the JS in express.static. The included JS sources at ../js from your index.html file go nowhere because client/views is the only directory being served by express.static.

您应该只包括整个客户端在静态,否则你就必须做包括每个目录到您的静态提供商。

You should just include the whole client in your static, otherwise you'll have to do include each directory into your static provider.

app.use(如press.static(__目录名称+'/客户/视图')); 表示要从/客户/意见,但任何服务该目录以外没有任何

app.use(express.static(__dirname + '/client/views')); means you are serving anything from /client/views but nothing OUTSIDE of that directory.

app.use(如press.static(__目录名称+'/客户/ JS')); 将允许您服务JS文件夹,但它将在根目录访问。您可以使用两种静态提供,但第一个将在冲突的情况下获胜。你也可以做 app.use(如press.static('/ JS',__dirname +'/客户/ JS')); 这将所有的你在 yoursite.com/js 访问客户端/ JS,但似乎我奇怪的。

app.use(express.static(__dirname + '/client/js')); would allow you to serve the JS folder, but it would be accessed at root. You can use TWO static providers but the first one will win in the event of a conflict. You could also do app.use(express.static('/js', __dirname + '/client/js')); which would all you to access client/js at yoursite.com/js but that seems strange to me.

阅读上使用这里前press.static:的http://恩pressjs.com / api.html#中间件

Read up on using express.static here: http://expressjs.com/api.html#middleware