Closed swatijadhav closed 9 years ago
Views are being replaced in favour of components. Anything that you'd do with views you can do in a component as well.
export default Ember.Component.extend({
didInsertElement() {
this.$().foundation({
offcanvas: { close_on_click: true }
});
}
});
Edit: Forgot the hook :)
Thanks.. I want to place it at application level.. the layout will have left sidebar (left canvas menu), which will be open on large screen and collapse on small screen, so its part of application layout.
So do i need to create separate template for above component? or can I directly use it in my application layout? Thanks :)
You can create an application component and put it into the application template. I would do something like this:
application.hbs
{{#app-canvas}}
<h2>Welcome to Ember.js</h2>
{{outlet}}
{{/app-canvas}}
components/app-canvas.js
export default Ember.Component.extend({
didInsertElement() {
this.$().foundation({
offcanvas: { close_on_click: true }
});
}
});
Edit: updated with the correction
Great Solution!! I will try this out and let you know.. Thanks :+1:
After adding above component, giving error as file changed components/app-canvas.js
browse/components/app-canvas.js: Unexpected token (2:6) SyntaxError: browse/components/app-canvas.js: Unexpected token (2:6) 1 | export default Ember.Component.extend({ > 2 | this.$().foundation({ | ^ 3 | offcanvas: { close_on_click: true } 4 | }); 5 | });
so added changes as
import Ember from "ember";
export default Ember.Component.extend({
didInitAttrs() {
Ember.run.schedule("afterRender", function() {
Ember.$(document).foundation({
offcanvas: { close_on_click: true }
});
});
},
});
Its working now!! Let me know if you have any suggestion @taras
Yes, Yes. I made a mistake in that code example.
No problem at all!! Once again thanks for the instant help :smile: We can close this issue now.
It's my pleasure. Tell you friends :)
> import Ember from "ember";
> export default Ember.Component.extend({
> didInitAttrs() {
> Ember.run.schedule("afterRender", function() {
> Ember.$(document).foundation({
> offcanvas: { close_on_click: true }
> });
> });
> },
> });
this isn't correct, @taras intermediate example is though:
> export default Ember.Component.extend({
> didInsertElement() {
> this.$().foundation({
> offcanvas: { close_on_click: true }
> });
> }
> });
@swatijadhav as @stefanpenner pointed out, you should use didInsertElement
rather than didInitAttrs
with afterRender
Thank you @stefanpenner for correcting us. @taras, yeah I have updated code. :+1:
I have used https://github.com/artificialio/ember-cli-foundation-sass in my ember, i created a component and in the component I used what is suggested here that didnt worked.
I found this code from another github page
initFoundation: Ember.on('didInsertElement', function () {
Ember.run.next(() => {
Ember.$(document).foundation();
});
})
It also didnt seemed to work. I am getting Uncaught TypeError: Ember.default.$(...).foundation is not a function
Error on page load
Please, create another issue with your question. thank you
I am working on ember application using ember-cli.
ember version is "2.0.0-beta.2"
I am integrating the foundation 5 in application, installed bower package for foundation and also included it in ember-cli-build.js file
Now i want to initialize the foundation as
But in ember-2 they have removed views completely, where should i initialize it?
Any thoughts?
Thanks.