【问题标题】:Aurelia quick start or my first app Hello World - No view model found error, 2017Aurelia 快速入门或我的第一个应用程序 Hello World - No view model found 错误,2017
【发布时间】:2017-03-22 01:44:08
【问题描述】:

在 angular2 和 reactjs 中做了一些小应用程序之后,这是我第一次尝试使用 Aurelia。 在快速启动之后,我的第一个应用程序出现错误,只是更新应用程序以显示“hello world”:

http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/quick-start/1

我有一个错误:

未捕获(承诺中)错误:在模块“src/app”中找不到视图模型。 在 aurelia-core.min.js:7

知道发生了什么吗?我不清楚这个错误; aurelia 管理好错误消息?

“视图模型”是指html模板文件?

/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Aurelia</title>
  </head>
  <body aurelia-app="src/main">
    <script src="scripts/system.js"></script>
    <script src="scripts/config-typescript.js"></script>
    <script src="scripts/aurelia-core.min.js"></script>
    <script>
      System.import('aurelia-bootstrapper');
    </script>
  </body>
</html>

/src/main.ts

import {Aurelia} from 'aurelia-framework';

export function configure(aurelia: Aurelia) {
  aurelia.use.basicConfiguration();
  aurelia.start().then(() => aurelia.setRoot());
}

更新:错误是 app.ts 是 app.ts 是空的!

/src/app.ts

export class App {
    heading = "Hello World";

}

/src/app.html

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

【问题讨论】:

  • 您可以发布您的 app.ts 文件内容吗?视图模型是 *.ts 文件,视图是 *.html 文件。
  • 感谢@Lakerfield,我的错误是我从快速入门网站粘贴 app.ts 内容后没有保存它,内容为空。昨天工作这么晚!

标签: aurelia


【解决方案1】:

错误是我的 app.ts 是空的,它产生“No view model found”

在 index.html 上,我们通过 main.js 或 main.ts 文件(如果我们使用 typescript)引导应用程序

/src/index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Aurelia</title>
  </head>
  <body aurelia-app="src/main">  <!-- Bootstrap here --> 
    <script src="scripts/system.js"></script>
    <script src="scripts/config-typescript.js"></script>
    <script src="scripts/aurelia-core.min.js"></script>
    <script>
      System.import('aurelia-bootstrapper');
    </script>
  </body>
</html>

Aurelia 有一个约定。它尝试查找 app.js 或 app.ts 并将其作为根模块加载。

/src/app.ts

export class App {
    heading = "Hello World";
}

【讨论】:

  • @JeffG 我需要等待 2 天
猜你喜欢
  • 1970-01-01
  • 2014-08-24
  • 1970-01-01
  • 1970-01-01
  • 2018-06-13
  • 2018-07-15
  • 1970-01-01
  • 2015-07-19
  • 2021-07-30
相关资源
最近更新 更多