Setting tagName on application template in ember j

2020-07-31 01:37发布

问题:

Views are deprecated in ember js. I want to set the tagName for the application template to "empty" because I don't want my content wrapped in a div - it messes up my css. Previously I have don this by creating an views/application.js and setting tagName: '' but views are deprecated - how can I do this without views?

回答1:

While I agree with the comments that this may not be something you want to do, you can use the ember-legacy-views addon until routable components are released.

Tagless components are also mentioned in the Component Unification RFC, which you might find interesting.



回答2:

[Reposting from this StackOverflow question]

You can control the top-level tag (even not rendering it), and its CSS classes by modifying your Ember Application as follows:

// app/app.js

App = Ember.Application.extend({
  ApplicationView: Ember.Component.extend({
    classNames: ['my-custom-classname'],
    // Or to omit the tag entirely:
    tagName: '',
  }),
  // ...
});

As seen in this discussion.

This does not require any hacks or a legacy plugin.