【问题标题】:angular js is not rendering in jade (with node.js)角度 js 没有在翡翠中呈现(使用 node.js)
【发布时间】:2013-12-05 10:02:40
【问题描述】:

我遇到的问题是我的 Angularjs 没有在我的 Jade 布局中呈现或加载。不知何故,手写笔可以完美地工作。我找不到原因。我还是学玉、手写笔和angularjs的初学者

以下是我的代码:

index.jade

!!! 5
html(ng-app='ng-app')
head
    script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js')
    script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-resource.min.js')
    script(src='https://cdn.firebase.com/v0/firebase.js')
    script(src='http://firebase.github.io/angularFire/angularFire.js')
    script(type='text/javascript', src='angular.js')
    link(rel='stylesheet', href='style.css')
  body
    .addressBook(ng-controller='addressBook')
      h1 Address Book
      table(width='710px', border='0', cellspacing='0', cellpadding='0')
        tr.title(height='35px', align='left')
          td(width='130') Name
          td(width='180') Email
          td(width='210') Address
          td(width='80') Mobile
        tr.details(ng-repeat='contact in contacts')
          td {{contact.name}}
          td {{contact.email}}
          td(style='padding-bottom: 30px;') {{contact.address}}
          td {{contact.mobile}}

angular.js

function addressBook($scope)
{
    $scope.contacts =
    [
        {name:'Peter', email:'john_peter@asd.co', address:'No.123, Road 12/20, Street Army, 58200 KL, Malaysia', mobile:'601231231234' },
        {name:'Lim', email:'Amy@asd.co', address:'54, 13/15, Happy Garden, 58200 KL, Malaysia', mobile:'60123473534' }

    ];
}

app.js

var jade = require('jade')
 , express = require('express')
 , http = require('http')
 , app = express();
 var stylus = require('stylus');
 require('./angular.js');

app.configure(function(){
    console.log('Configuring views....');
    app.set('port', 1234);
    app.set('views', './');
    app.use(express.bodyParser());
    app.use(express.static( __dirname + '/'));
    app.set('view engine', 'jade');
});

app.get('/test', function(req,res){
    res.render('index.jade');
});

server = http.createServer(app);
server.listen(app.get('port'), function(){
}).on('error', function(err) {
   throw err;
});

感谢所有帮助的人

【问题讨论】:

    标签: node.js angularjs render pug stylus


    【解决方案1】:

    我怀疑您遇到的问题是您指定的视图路径是错误的,并且您正在静态地提供它们。

    例如,如果您的视图位于基本目录的子目录中,并且您已将基本目录设置为作为静态内容提供,则它将玉作为静态内容提供。

    您应该做的是将您的视图放在与静态内容不同的文件夹中,以便它是兄弟而不是孩子,这应该可以工作。如果你想发布你的目录结构我可以看看。

    【讨论】:

      猜你喜欢
      • 2012-03-20
      • 2015-12-09
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多