Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 玉中有棱角。_Angularjs_Express_Pug_Angularjs Ng Include - Fatal编程技术网

Angularjs 玉中有棱角。

Angularjs 玉中有棱角。,angularjs,express,pug,angularjs-ng-include,Angularjs,Express,Pug,Angularjs Ng Include,我正在尝试使用ng include from Angular将标题包含到我的Jade模板中: doctype html html(lang="en") head meta(charset='UTF-8') meta(name='fragment', content='!') base(href='/') title Node Express Angular link(rel='stylesheet', hre

我正在尝试使用ng include from Angular将标题包含到我的Jade模板中:

doctype html
html(lang="en")
    head
        meta(charset='UTF-8')
        meta(name='fragment', content='!')
        base(href='/')
        title Node Express Angular
        link(rel='stylesheet', href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css')
        link(rel='stylesheet', href='/css/syle.css')
    body(ng-app='myApp')
        ng-include(src='\'/partials/header.jade\'')
        div.container
            div.jumbotron.text-center
                h1 Home Page
                p This page is a draft in progress
        script(src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.15/angular.min.js')
        script(src='//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js')
        script(src='/js/app.js')
header.jade中的文本如下所示:

nav.navbar.navbar-inverse(role='navigation')
ul.nav.navbar-nav.navbar-header
    li
        a(src='/home', class='navbar-brand') Home
    li
        a(src='/about') About
    li
        a(src='/login') Login
    li
        a(src='/register') Register
我尝试了
nginclude(src='\'/partials/header.jade\'')和
div(ng include='\'/partials/header.jade\'')

在Chrome开发者控制台中,第一个结果是
,第二个结果是:

有什么线索吗?

请使用下面的代码查阅官方文件

div(ng include=“'partials/header.jade'”)

如果要直接使用ngInclude指令,请使用


ng include(src=“'partials/header.jade')
您使用Angular的
ng include
而不是jade自己的include机制有什么具体原因吗

body(ng-app='myApp')
    include partials/header

参考表单。

我创建了一个Angular指令,由JADE呈现,然后由Angular编译到给定的范围。。。。而且它有效

顺便说一句,我正在为浏览器使用客户端Jade,CDN可用

例如:

html:


MyPageWithJadeScript.html:

<jade>tag#id.class jade text</jade>
tag#id.class文本
角度:

app
.directive('jade',function($compile){
return{
    transclude: true,
    template: '<div ng-transclude></div>',
    restrict: 'E',
    link: function(scope, element){
      element
        .after(
          $compile(
            jade
            .render(
                element.html(),
                {pretty:'\t'}
            )
          )(scope)
        )
        .remove();
    }
};
});
app
.directive('jade',函数($compile){
返回{
是的,
模板:“”,
限制:'E',
链接:功能(范围、元素){
要素
.之后(
$compile(
玉
.渲染(
element.html(),
{pretty:'\t'}
)
)(范围)
)
.remove();
}
};
});

希望您能找到有用的

使用express,我在视图/文件夹中有文件user-description.jade,要将其包含在另一个jade文件中,我只需使用以下表达式:

div
  include user-description.jade

有其他示例。

我尝试了这两种方法,但都没有呈现我的文件头.jade的内容。我之前确实检查过我的jade文件的内容是否有效。删除
base(href='/')
怎么样?您检查过模板引擎了吗?也许你可以试试
div(ng include=“'partials/header.html]”)
我已经试过了,我已经创建了一个header.html,并且显然已经将它从jade转换成了html。也不管用。谢谢,这个管用。不,除了尝试结合玉和角之外,没有任何具体的原因。不是很直截了当什么应该处理什么。好的,很好。这就是我们如何在我当前的项目中包含部分,我只是想知道这是否缺少您想要的东西。(那“有什么特别的原因”在我看来现在有点粗糙了…)不用担心,玉和角都可以做很多事情,我正在努力区分哪一个最适合每一个目的。我喜欢这个解决方案,因为它绕过了使用
ng include
时遇到的范围问题。我认为当要包含的部分是静态内容且不包含角度逻辑时,它也更为惯用。
div
  include user-description.jade