[英]From within an ember component life cycle hook, how can I determine if the component is being invoked in block form?
Per the Ember guides , you can determine if a component is being rendered in block format from within the template using the hasBlock
keyword: 根据Ember指南 ,您可以使用
hasBlock
关键字确定是否从模板中以块格式呈现组件:
// foo-component.hbs
{{#if hasBlock}}
block mode
{{else}}
something else
{{/if}}
How do I do this from within foo-component.js
? 我该如何在
foo-component.js
执行此操作?
import Ember from 'ember';
export default Ember.Component.extend({
didInitAttrs: function() {
// hasBlock is not defined here
if ( this.get('hasBlock') ) {
}
}
});
You could check for template
property of Component, but such behavior is deprecated: 您可以检查Component的
template
属性,但是不建议使用这种行为:
if (this.get('template')) {
console.log('Component has block!');
}
根据sbatson的评论,不支持在模板中使用hasBlock
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.