I'm trying to include a header, using ng-include from Angular into my Jade template:

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')

The text in header.jade is the following:

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

I have tried both ng-include(src='\'/partials/header.jade\'') and div(ng-include='\'/partials/header.jade\'')

In the Chrome developer console, the first one results in <!--ng-Include: undefined --> and the second: <!-- ng-Include: '/partials/header.jade' -->

Any clues?

有帮助吗?

解决方案

Is there a specific reason why you're using Angular's ng-include instead of Jade's own include mechanism?

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

Reference form the the Jade docs.

其他提示

I created an Angular directive to be rendered by JADE and then compiled by Angular to the given scope.... and it works!

btw,I'm using client-side Jade for browsers, the CDN is available here

for e.g:

html:

<ng-include src="'MyPageWithJadeScript.html'"></ng-include>

MyPageWithJadeScript.html:

<jade>tag#id.class jade text</jade>

angular:

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();
    }
};
});

Hope you find this useful

Refer to official doc ngInclude, using the code below

div(ng-include="'partials/header.jade'")

If you want to use ngInclude directive directly, use

ng-include(src="'partials/header.jade'")

Using express, I have the file user-description.jade inside of the views/ folder and to include it in another jade file I simple use the following expression:

div
  include user-description.jade

Jade docs has other samples.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top