-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hasBlock not available in component init #11741
Comments
In general, I would suggest not trying to do different things in your components JS code based on if a block was supplied. It is much better to do this sort of thing from the template instead. |
Doing it in the component would work as well, of course. The only issue I had with doing that is that it fails silently at runtime. |
I think it can make sense to expose it in the component as well. I need to set a class depending on the presence of a block or not on the root element. I don't think this is possible with components now (with tagless components it will of course). |
Just came across this issue...I have the same need. In my case, the CSS class applied will change depending if there is a block. |
+1 for using this in JS code (to be used for example in classNameBindings) |
+1 |
+1 what I want is just add a class name binding related to hasBlock property since your document mentioned about this property http://emberjs.com/api/classes/Ember.Component.html#property_hasBlock, and you didn't say it can only be used in template at all. |
This is fine unless you have complex logic to decide if you want to show the block, then your template becomes very messy and you need to write lots of logic helpers just because you can't move the logic to your js file |
I also expected to be able to reference |
I'll also 👍 this request. We want to mimic the behaviour of the This has been done in the Ember code base in the LinkComponent by using If the core team is not willing to open up to this request, can I get help about how to implement similar behaviour as the one of |
another scenario where this is very nice to have.. messageBannerText: computed(function() {
if (!this.get('hasBlock')) {
throw new Error("messageBannerText must be passed into {{generic-banner ...}}");
}
}), I'd like to keep this convenient way to aid a developer in using my component, but i don't want it to erroneously force a value when a block has been provided instead |
When initialising a component I want to checker whether it was called with a block or not. (If it's not called with a block a parameter should be set on the component).
While this works fine in the template, the following code does not behave as expected in the component:
Should this be possible or would you consider that a bad practice?
The text was updated successfully, but these errors were encountered: