Trom
Trom

Reputation: 65

Injector.modulerr error using angular.js

I've got a problem with node-jade-angular app: layout.jade

doctype html
html(ng-app='listApp')
    head
        title= title
        script(src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js')
        script(src='javascripts/controller.js')
        script var listApp = angular.module('listApp', ['ngRoute'])
    body
        block content

index.jade

extends layout

block content

    .jumbotron
        p Welcome to #{title}
    hr
    table(ng-controller='listAppCtrl')
        tr
            th name
            th lastname
        tr(ng-repeat='m in docs')
            td {{m.name}}
            td {{m.lastname}}

route.js

exports.home = function (req, res, next) {
    model.find(function (err, docs) {
        if (err) return next(err);
        res.render('index', {title: 'Title', docs: docs});
    })
}

And controller.js

function listAppCtrl($scope) {
    $scope.docs = docs;
}

If I try to get all db without angular, I get

{ _id: 53c42d38641e36ec1397d7d1, name: 'inserting 1405365560178', __v: 0 },{ _id: 53c42d45641e36ec1397d7d2, name: 'inserting 1405365573837', __v: 0 },{ _id: 53c7f581a4dc859014c062cc, name: 'inserting 1405613441718', lastname: '0.2614648900926113', __v: 0 }

however with code above, i always get Error: [$injector:modulerr]

Upvotes: 2

Views: 441

Answers (1)

runTarm
runTarm

Reputation: 11547

Your listApp module require the ngRoute module, so you have to include the angular-route.js as well.

ngRoute url: http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular-route.min.js

As an general advise, you could change to use an un-minified version of angularjs, that will give you a more meaningful error like Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module ....

Unminified angularjs: http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.js

PS. angular 1.2.10 is quite old, please consider using the latest version.

Upvotes: 1

Related Questions