繁体   English   中英

如何使用Angular和Express 4.0渲染局部文件和Jade文件?

[英]How do I render partials and jade files with Angular and Express 4.0?

我在网上看了几个地方,但大多数地方是Express 2-3。 我知道我需要将有关局部的信息放在某个地方,但是我不知道在哪里或如何精确地将其映射出来。 基本上,我的页面从'/'到'/ game',我想在那里拥有一个SPA,但是在页面内渲染玉器模板时遇到了问题。 我复制了一个测试页,但由于尝试从/ views或/ partials加载某些内容而导致崩溃。 由于我的页面变得不适合索引使用,所以我不知道将有关局部代码的位置放在哪里。 在app.js中? 在game.js中? 在index.js中? 别的地方? 那我到底要放什么呢?

在layout.js中

doctype html
html
  head
    title test title
     script(src='http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js')
    script(src='http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-route.min.js')
    script(src='script.js')
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    block content

在app.js中

// catch-all route so non-explicitly defined routes load angular routes
app.get('*', function(req, res){
    res.render('home'); //
});

玉器

extends layout
block content
  body(ng-app='RoutingApp')
    h2 AngularJS Routing Example
    p
      | Jump to the 
      a(href='#first') first
      |  or 
      a(href='#second') second page
    div(ng-view='')

script.js

var app = angular.module('RoutingApp', ['ngRoute']);

app.config( ['$routeProvider', function($routeProvider) 
    {
    $routeProvider
        .when('/first', {
            // templateUrl: 'views/last' // THIS CRASHES THE PAGE
            // templateUrl: 'last' // so does this
            templateUrl: 'last.jade' // this doesn't, but serves up static file instead of rendering jade
        })
        .when('/second', {
            templateUrl: 'second.html'
        })
        .otherwise({
            redirectTo: '/'
        });
    }]);

路线已在/中注册,因此您需要将href用作#/first#/second

p
  | Jump to the 
  a(href='#/first') first
  |  or 
  a(href='#/second') second page

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM