简体   繁体   中英

How to set the tagName of an Ember component based data in the model?

I would like to set the tagName of an ember component based on data in the model like this:

App.TestComponent = Ember.Component.extend({
    tagName: function(){return this.get('tag');}.property('tag')
});

This doesn't work though. The W3C specifies that you can't change the tagName of an element, so I can see why binding a variable to a static property would be problematic - just not sure how to accomplish this.

Any ideas?

Use tagName

{{test-foo tagName=item}}

http://emberjs.jsbin.com/molamohi/1/edit

http://emberjs.jsbin.com/vowur/3/edit shows how to set the tagName of a Component based on a property in a model object. Specifically:

{{test-component someVal=model.val tagName=model.tag}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM