简体   繁体   中英

How to use layouts in Aurelia?

Aurelia recently added support for layouts, and they roughly explained those in their documentation .

However, while I managed to get the layouting itself to work, I cannot use any variables in my layout-HTML which I have as properties in my Layout-ViewModel.

A MWE:

app.ts

import {Router, RouterConfiguration} from 'aurelia-router';

export class App {
  router: Router;

  configureRouter(config: RouterConfiguration, router: Router) {
    config.map([
      { route: 'hello', layoutViewModel: 'layout/main', moduleId: 'hello/index' },
    ]);
  }
}

layout/main.ts

export class MainLayout {
  heading = 'Hallo Welt';
}

layout/main.html

<template>
  <h1>${heading}!</h1>
</template

But only the exclamation point occurs. Do you have any ideas what I am doing wrong or how I can get it to work?

Many thanks in advance!

Sorry for the delayed answer here, but your example appears to be working for me. It is highly possible that you experienced a bug that has since been fixed or an issue elsewhere in your code.

Please see this linked Gist.run example to see your example running.

github上有一个关于同样问题的问题https://github.com/aurelia/templating-router/issues/34它已经解决了,现在layoutViewModel绑定得很好。

You could do this in layout/main.ts:

export class MainLayout {
  constructor() {
    this.heading = 'Hallo Welt';
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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