user3481061
user3481061

Reputation: 11

$injector:modulerr AngularJS, tried everything so far

I am new to angular and I am following the tutorial on angularjs website

What I tried so far:

I am trying to solve this error for two days now. Please help me :(

Here is my code:

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;

edit:

I found the problem. when I insert '/' beginning of the script includes the problem was solved. It was because the path should be absolute in order to find scripts even from subdirectories. Thank you all.

Upvotes: 1

Views: 53

Answers (1)

micronyks
micronyks

Reputation: 55443

What I have understood is your module name is mismatched. Make it correct everywhere (Case-sensitive).

var phonecatApp = angular.module('phonecatApp', ['ngRoute']); // your module Name...

html(ng-app="phoneCatApp") // your declaration of module. mismatched.

If you still find trouble, you may referrer to this link,

http://jsfiddle.net/micronyks/8RG7y/

Note: This is just a basic demo (without Jade, Node.js, Express)

Upvotes: 1

Related Questions