問題をできるだけ詳しく説明します。
Express で AngularJS を使用しようとしていますが、問題が発生しています。HTML ファイルを表示したい (テンプレート エンジンを使用しない)。これらの HTML ファイルには AngularJS ディレクティブが含まれます。
ただし、単純な HTML ファイル自体を表示することはできません。
ディレクトリ構造は次のとおりです。
Root
---->public
-------->js
------------>app.js
------------>controllers.js
---->views
-------->index.html
-------->partials
------------>test.html
---->app.js
の内容public/js/app.js
は次のとおりです。
angular.module('myApp', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {templateUrl: 'partials/test.html', controller: IndexCtrl});
$routeProvider.otherwise({redirectTo: '/'});
}]);
の内容public/js/controllers/js
は次のとおりです。
function IndexCtrl() {
}
body タグの内容views/index.html
は次のとおりです。
<div ng-view></div>
それでおしまい。期待されるのは、AngularJS が上記のビューを test.html に置き換えることですviews/partials/test.html
。その内容は次のとおりです。
This is the test page!
段落タグで囲みます。それでおしまい!
最後に、ROOT/app.js
ファイルの内容は次のとおりです。
var express = require('express');
var app = module.exports = express();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/public'));
app.use(app.router);
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// routes
app.get('/', function(request, response) {
response.render('index.html');
});
// Start server
app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
これ$node app.js
で、ルート フォルダーで実行すると、サーバーはエラーなしで起動します。ただしlocalhost:3000
、ブラウザで にアクセスすると、URL が に変わりlocalhost:3000/#/
、ページが動かなくなったりフリーズしたりします。Chrome でコンソール ログを確認することさえできません。
これが私が直面している問題です。私が間違っていることについての手がかりはありますか?