如何使用Ember CLI在两个组件之间共享模板?

Nud*_*oll 3 ember.js ember-cli

我有两个组成部分:SpecialButtonComponentSpecialButtonDerivativeComponent.

SpecialButton组件自动使用在的模板/app/templates/components/special-button.hbs.

我想SpecialButtonDerivativeComponent使用相同的模板,但到目前为止,我没有运气尝试使用这种技术:

// app/components/special-button-derivative.js
import SpecialButtonComponent from './special-button';

export default SpecialButtonComponent.extend({
  templateName: 'components/special-button'
});
Run Code Online (Sandbox Code Playgroud)

我也尝试使用layoutName而不是templateName,但仍然没有运气.有任何想法吗?

giv*_*nse 6

组件没有templateName.

我会尝试设置layout为null然后指定一个layoutName.

  • 在ember 2.0中,不需要该属性,但您必须确保扩展组件没有创建模板文件.因为如果有一个模板文件,它将覆盖继承的模板.所以一定要删除它的模板:) (3认同)