Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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
Javascript aurelia:自定义组件中未打印变量_Javascript_Aurelia - Fatal编程技术网

Javascript aurelia:自定义组件中未打印变量

Javascript aurelia:自定义组件中未打印变量,javascript,aurelia,Javascript,Aurelia,weather.ts文件 import {bindable} from 'aurelia-framework'; export class Weather { cityName: string = 'Hilsinki'; constructor() { this.cityName = 'Hilsinki'; } } <template> City XName: ${cityName} </template> weather.htm

weather.ts文件

import {bindable} from 'aurelia-framework';

export class Weather {
  cityName: string = 'Hilsinki';
  constructor() {
    this.cityName = 'Hilsinki';
  }
}
<template>
        City XName: ${cityName}
</template>
weather.html文件

import {bindable} from 'aurelia-framework';

export class Weather {
  cityName: string = 'Hilsinki';
  constructor() {
    this.cityName = 'Hilsinki';
  }
}
<template>
        City XName: ${cityName}
</template>

您不需要查看模型,只需要查看

<require from = "./components/weather.html"></require>

如果同时需要视图和viewmodel,请改为如下要求:

<require from = "./components/weather"></require>


您是如何包含该组件的?我们能看到创建
组件的HTML文件吗?@JessedBruijne,谢谢,更新后,请检查更新后的错误:同名元素已经存在。再次包含该元素时会出现此错误。检查代码中的其他位置以查看是否包含该元素,然后在此处/此处将其删除错误:尝试注册具有相同名称的元素时已存在该元素。名称:weather。您需要从“/components/weather”中删除
view model=“weather”
import{weather},因为它们不再是必需的:)