我是角色新手,我正在关注angularjs网站上的教程
到目前为止我尝试了什么:
我正试图解决这个错误两天了。请帮帮我:(
这是我的代码:
layout.jade:
doctype html
html(ng-app="phoneCatApp")
head
meta(charset="utf-8")
script(src='lib/angular/angular.min.js')
script(src='lib/angular-route/angular-route.min.js')
script(src='js/controllers.js')
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body(ng-controller="PhoneListCtrl")
block content
index.jade:
extends layout
block content
ul
li(ng-repeat="phone in phones")
span {{phone.name}}
p {{phone.snıppet}}
controller.js:
var phonecatApp = angular.module('phonecatApp', ['ngRoute']);
phonecatApp.controller('PhoneListCtrl', function ($scope) {
$scope.phones = [
{
'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'
},
{
'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'
},
{
'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.'
}
];
});
index.js:
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function (req, res) {
res.render('index', { title: 'Express' });
});
module.exports = router;
app.js:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
//app.use('/', routes);
//app.use('/users', users);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
编辑:
我发现了问题。当我插入'/'开头的脚本包含问题就解决了。这是因为路径应该是绝对的,以便甚至从子目录中查找脚本。谢谢大家。
答案 0 :(得分:1)
我所理解的是您的模块名称不匹配。使其在任何地方都正确(区分大小写)。
var phonecatApp = angular.module('phonecatApp', ['ngRoute']); // your module Name...
html(ng-app="phoneCatApp") // your declaration of module. mismatched.
如果您仍然遇到问题,可以推荐此链接,
http://jsfiddle.net/micronyks/8RG7y/
注意:这只是一个基本的演示(没有Jade,Node.js,Express)