[英]Dynamically determine existence of template only Ember glimmer component?
我知道要動態確定 Ember 上某個組件的存在,我們可以使用此處或此處說明的解決方案。
我們有一個使用.hasRegistration('component:${component}')
的助手
只要定義了 .js 文件,這也適用於 Glimmer 組件,但不適用於僅模板的 Glimmer 組件。 在這種情況下,該組件似乎沒有注冊。
有誰知道也適用於僅模板微光組件的解決方案?
我在 stackblitz 上為你做了一個演示:
https://stackblitz.com/edit/github-k7htnb?file=app%2Fcomponents%2Fdemo.hbs
{
"component:template-only": true,
"template:template-only": false
}
這是顯示您正在執行的操作在 Ember 3.28 中有效的代碼:
<pre>{{this.format this.results}}</pre>
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { getOwner } from '@ember/application';
export default class Demo extends Component {
format = (data) => JSON.stringify(data, null, 2);
@tracked name = 'template-only';
get results() {
let owner = getOwner(this);
let name = this.name;
return {
[`component:${name}`]: owner.hasRegistration(`component:${name}`),
// added this for curiosity
[`template:${name}`]: owner.hasRegistration(`template:${name}`),
};
}
}
現在,如果我將 ember-source 更改為 3.26.1,它是一樣的。
也許您正在做的事情和這個演示正在做的事情之間存在輕微的代碼不匹配?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.