我正在使用 Angular、express、nodeJS 进行 Web 应用程序开发。
角码:
'use strict';
//
Declare app level module which depends on filters, and services
angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'});
$routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
$routeProvider.otherwise({redirectTo: '/view1'});
}]).config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode(true);
}]);;
angular.module('modelDemo', []).
config(function ($routeProvider) {
$routeProvider.
when('/', {
controller: 'AuthorListCtrl',
templateUrl: 'partials/list.html'
});
$routeProvider.
when('/view1', {
controller: 'MyCtrl1',
templateUrl: 'partials/partial1.html'
});
$routeProvider.otherwise({redirectTo: '/view1'})
});
var app = angular.module('app', ['myApp', 'modelDemo']);
快递代码
// all environments
app.set('port', process.env.PORT || 2000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);
app.get('/', wine.index);
app.get('/partials/:name', wine.partials);
app.get('/wines', wine.findAll);
// / app.get('/view1', wine.index);
app.get('/wines/:id', wine.findById);
app.post('/wines', wine.addWine);
app.put('/wines/:id', wine.updateWine);
app.delete('/wines/:id', wine.deleteWine);
app.get('/view1', wine.partials);
//app.get('/view1/:name', wine.partials);
2)
exports.index = function(req, res){
console.log("request url---"+req.url);
res.render('partials/' + req.params.name);
};
exports.partials = function(req, res) {
console.log("request url---"+req.url);
console.log(req.params.name);
res.render('partials/' + req.params.name);
};
项目文件夹结构:
当我尝试使用以下网址访问此应用程序时, http://www.domain:2000/view1
我收到以下错误,
错误:无法在 ServerResponse.res.render (d:\era\startup\learnnod\restfull_angular2\node_modules\express\lib\application.js:494:17) 的 Function.app.render ( d:\era\startup\learnnod\restfull_angular2\node_modules\express\lib\response.js:756:7) 在exports.partials (d:\era\startup\learnnod\restfull_angular2\routes\wines.js:104:9 ) 在回调 (d:\era\startup\learnnod\restfull_angular2\node_modules\express\lib\router\index.js:161:37) 在参数 (d:\era\startup\learnnod\restfull_angular2\node_modules\express\lib \router\index.js:135:11) 通过 (d:\era\startup\learnnod\restfull_angular2\node_modules\express\lib\router\index.js:142:5) 在 Router._dispatch (d:\era \startup\learnnod\restfull_angular2\node_modules\express\lib\router\index.js:170:5) 在 Object.router (d:\era\startup\learnnod\restfull_angular2\node_modules\express\lib\router\index.js:33:10) 在下一个 (d:\era\startup\learnnod\restfull_angular2\node_modules\express\node_modules\connect\lib\proto .js:190:15) 在简历 (d:\era\startup\learnnod\restfull_angular2\node_modules\express\node_modules\connect\lib\middleware\static.js:60:7)
如果您需要更多信息,请告诉我