How do I customize the view element for the application.hbs template?

丶灬走出姿态 提交于 2019-12-09 21:03:00

问题


In an app generated by ember-cli, the html generated by application.hbs is wrapped in a view:

<body class="ember-application">
  <div id="ember284" class="ember-view">
  </div>
</body>

If I create a component, I have a component-name.js file where I can specify options to modify the component:

export default Ember.Component.extend({
  tagName: 'nav',
  classNames: ['main-menu'],
  layout: layout
});

How do I modify the attributes of the element that is wrapping the application.hbs template?


回答1:


create a file in the app/views directory that follows the naming conventions, application.js

import Ember from "ember";

export default Ember.View.extend({
  classNames: ['my-app-view']
  // this is the application view
});

Now confirm it works by inspecting your html:

<body class="ember-application">
  <div id="ember287" class="ember-view my-app-view">
    <h2 id="title">Welcome to Ember.js</h2>
  </div>
</body>



回答2:


The Ember.View direct access is deprecated starting from version 2.x. What they did, is they have converted the Ember.View to an abstract class. Now you should use Ember.Component. As the short-cut, you could try something like this:

// app/views/application.js
import Ember from 'ember';

export default Ember.Component.extend({
  classNames: ['customClassName']
});


来源:https://stackoverflow.com/questions/29177037/how-do-i-customize-the-view-element-for-the-application-hbs-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!