How do i get the container name of a component within itself?
this.componentNameStream
used to kind of work in 1.11.
// in components/my-component.js
export default Component.extend({
layoutName: "components/my-component",
partialName: function() {
//return "my-component"; somehow....
}.property();
});
why? for subclassing reasons:
// in components/blah.js
export default MyComponent.extend({});
// in templates/components/my-component.hbs
<div class="someLayout">
// partialName is now "components/blah"
{{ partial partialName }}
</div>
答案 0 :(得分:0)
我不确定我完全理解你要做什么,但不建议使用{{partial}}
(参见https://github.com/dockyard/styleguides/blob/master/ember.md#templates)。
为什么不使用layoutName
简单地在两个组件之间共享模板?
// in components/my-foo.js
export default Component.extend({
showSomething: false
});
// in components/my-bar.js
export default MyFooComponent.extend({
layoutName: "components/my-foo",
showSomething: true
});
// in templates/components/my-foo.hbs
<div class="someLayout">
{{#if showSomething}}
I am the bar component!
{{/if}}
</div>
如果你真的需要使用partial,你可以用一个包含要显示为字符串的partial名称的属性替换showSomething
。