使用angular.js的Injector.modulerr错误

时间:2014-07-26 13:54:26

标签: node.js angularjs express pug

我遇到了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});
    })
}

和controller.js

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

如果我试图获得没有角度的所有数据库,我会得到

  

{_id:53c42d38641e36ec1397d7d1,名称:'插入1405365560178',__ v:0},{_ id:53c42d45641e36ec1397d7d2,名称:'插入1405365573837',__ v:0},{_ id: 53c7f581a4dc859014c062cc,名称:'插入1405613441718',姓氏:' 0.2614648900926113',__ v:0}

然而,使用上面的代码,我总是得到 错误:[$ injector:modulerr]

1 个答案:

答案 0 :(得分:1)

您的listApp模块需要ngRoute模块,因此您还必须包含angular-route.js

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

作为一般建议,您可以更改为使用未缩小版本的angularjs,这将为您提供更有意义的错误,例如Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module ...

未公开的angularjs: http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.js

PS。角度1.2.10很旧,请考虑使用最新版本。