javascript - 无法在 ng-view 内渲染 jade

标签 javascript node.js pug ng-view

我无法在 ng-view 内渲染 Jade。在ng-view之外, Jade 作品的渲染也正如想象中的一样。

我的猜测是我必须添加一个新的路由来渲染 home.jade 的内容,但这似乎不起作用。

您对如何解决此问题有什么建议吗?

快速路由

router.route('/')
    .get(function(req, res) {
        res.render(path.join(__dirname, '../views/', 'index'));
        // res.render(path.join(__dirname, '../views/partials', 'home'));
    });

layout.jade

doctype html
html(ng-app="myapp", lang="nl")
    head
        meta(charset="utf-8")
        meta(name="viewport", content="width=device-width, initial-scale=1") 
        link(rel='stylesheet', href='/stylesheets/style.css')
        link(rel='stylesheet', href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css')
        link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css')
        link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css')
        title MyApp
    body
    block content

    script(src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.js')
    script(src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js')
    script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js")
    script(src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular-route.js")
    script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js')
    script(src='/javascripts/app.js')
    script(src='/javascripts/my.js')

index.jade

extends layout

block content
    div#wrapper.container-fluid
    div#header.row-fluid
        h1 Document Heading
    div#nav.row-fluid
        ul.nav.nav-pills#top-nav
            li(role='presentation')
                a(href='/') Home
            li(role='presentation') 
                a(href='/about') About
            li(role='presentation') 
                a(href='/api-tester') API-tester
    div.row-fluid
        div#sidebar.col-md-2.hidden-xs
            h2 Column 2
            p Lorem ipsum dolor sit amet
            ul.nav.nav-pills.nav-stacked
                li(role='presentation') 
                    a(href='#') Link1
                li(role='presentation') 
                    a(href='#') Link2            
        div#main.col-md-10(ng-view)
    div#footer.row-fluid
        p Footer

partials/home.jade --> 不渲染

h1 Home

结果:

enter image description here

编辑:

我添加了一条新路线,但它仍然没有渲染

router.route('/partials/:name')
    .get(function (req, res) { 
        var name = req.params.name;
        res.render(path.join(__dirname, '../views/partials/', name));
    }
);

最佳答案

My guess is that I have to add a new route to render the content of home.jade, but that does not seem to work.

嗯,你的猜测是对的。您需要添加一条新路线来渲染 .jade 部分。 看看这个答案:https://stackoverflow.com/a/18747341/3130006

关于javascript - 无法在 ng-view 内渲染 jade,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32186177/

相关文章:

javascript - 如何将每个选项卡链接到抽屉导航?

javascript - AngularJS 从外部 ng-repeat 访问范围

javascript - React 组件未使用 if 语句在 .map 内渲染

node.js - React 路由器、nginx、 Node 、静态文件

node.js - 我想使用 jade/pug 将对象数组中的每个元素可视化到表格中

javascript - 如何使用 jQuery 在 IE 中滚动到页面顶部

javascript - Firebase 函数错误 - firebase.functions 不是函数

javascript - 为什么我的 pg-query 结果抛出 TypeError

node.js - 创建一个包含用户信息的jade默认布局

html - Bootstrap SASS 网格的错误列填充