Javascript aurelia:自定义组件中未打印变量
weather.ts文件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
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},因为它们不再是必需的:)