admin管理员组文章数量:1327936
I'm currently trying to learn Aurelia I've managed to use the aurelia-cli to set up a basic app and I'm now trying to build a custom ponent. I had the impression of Aurelia that I could set up a structure like this:
> /app_folder
> -- /src
> ---- app.html (root ponent view)
> ---- app.js (root ponent view-model)
> ---- /ponents
> ------ /my-ponent
> -------- my-ponent.html (custom ponent view)
> -------- my-ponent.js (custom ponent view-model)
In app.js I have managed to get my ponent to load using the <require>
tag in the view:
<require from = "./ponents/my-ponent/my-ponent.html"></require>
and then added that tag to the view:
<my-ponent />
This works exactly as I expected, however that ponent seems to be ignoring the view-model.
Currently my ponent view looks like this:
<template>
<h1>${header}</h1>
<span>Non-dynamic data for testing</span>
</template>
and it's view-model looks like this:
export class MyComponent {
constructor() {
this.header = 'Service started!';
}
}
When I run my app all I see is the span with the non-dynamic data in. The HTML output from the console looks like this:
<my-ponent class="au-target" au-target-id="3">
<h1></h1>
<span>Non-dynamic data for testing</span>
</my-ponent>
Can someone please tell me where I'm going wrong?
I'm currently trying to learn Aurelia I've managed to use the aurelia-cli to set up a basic app and I'm now trying to build a custom ponent. I had the impression of Aurelia that I could set up a structure like this:
> /app_folder
> -- /src
> ---- app.html (root ponent view)
> ---- app.js (root ponent view-model)
> ---- /ponents
> ------ /my-ponent
> -------- my-ponent.html (custom ponent view)
> -------- my-ponent.js (custom ponent view-model)
In app.js I have managed to get my ponent to load using the <require>
tag in the view:
<require from = "./ponents/my-ponent/my-ponent.html"></require>
and then added that tag to the view:
<my-ponent />
This works exactly as I expected, however that ponent seems to be ignoring the view-model.
Currently my ponent view looks like this:
<template>
<h1>${header}</h1>
<span>Non-dynamic data for testing</span>
</template>
and it's view-model looks like this:
export class MyComponent {
constructor() {
this.header = 'Service started!';
}
}
When I run my app all I see is the span with the non-dynamic data in. The HTML output from the console looks like this:
<my-ponent class="au-target" au-target-id="3">
<h1></h1>
<span>Non-dynamic data for testing</span>
</my-ponent>
Can someone please tell me where I'm going wrong?
Share asked Dec 15, 2016 at 16:06 Alex FoxleighAlex Foxleigh 1,9742 gold badges22 silver badges52 bronze badges1 Answer
Reset to default 13By putting:
<require from = "./ponents/my-ponent/my-ponent.html"></require>
You are only requiring the HTML template. Change this line to:
<require from = "./ponents/my-ponent/my-ponent"></require>
And it should work fine.
Also, the CLI has built-in generators: run au generate element
to automatically create a template that you can easily modify.
本文标签: javascriptAurelia component not loading viewmodelStack Overflow
版权声明:本文标题:javascript - Aurelia component not loading view-model - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742232043a2437396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论