Skip to content
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

onOpen and onClose Params #354

Closed
maurocappe opened this issue Aug 14, 2017 · 6 comments
Closed

onOpen and onClose Params #354

maurocappe opened this issue Aug 14, 2017 · 6 comments

Comments

@maurocappe
Copy link

I am having trouble with the onOpen and onClose options materialize css provides. Are they not supported by angular2-materialize? i am trying to use them to make the sidenav push the content of the page instead of overlaying on top.
Here's the code:

openNav() { document.getElementById('body').style.marginLeft = '300px'; document.getElementById('sideNav').style.width = '300px'; document.getElementById('sideNav').style.visibility = 'active'; document.body.style.backgroundColor = 'rgba(0,0,0,0.4)'; document.body.style.backgroundColor = '#176EB1'; }

closeNav() { document.getElementById('body').style.marginLeft = '0px'; }

<a href="#" data-activates="sideNav" materialize="sideNav" [materializeParams]="[{onOpen: openNav(), onClose: closeNav()}]" class="nav-link button-collapse left"><i class="material-icons">menu</i></a></li>

@KyDenZ
Copy link

KyDenZ commented Aug 15, 2017

Hello,

I have the same question about the datepiker(date & time), how to call a function when the modal datepicker is closed.

Thank you

@rubyboy
Copy link
Contributor

rubyboy commented Aug 17, 2017

@KyDenZ here's an example of datepicker binding to onClose:

@Component({
    selector: "datePicker",
    template: `
            <input materialize="pickadate"
                   [materializeParams]="[{format: 'dd/mm/yyyy', onClose: doSomething }]"
                   type="text" />
        `
})
export class DatePicker {

    doSomething() {
        console.log("here!");
    }
}

@maurocappe looking at youre code I see that the onOpen/onClose just calls the function when it's initialized. Remove the braces to make it a reference to a function and it should work (make it onOpen:openNav, onClose:closeNav).

@KyDenZ
Copy link

KyDenZ commented Aug 17, 2017

Perfect thank you !

@maurocappe
Copy link
Author

maurocappe commented Aug 17, 2017

oh... well.. rookie mistake.
Thanks a lot.

@rubyboy rubyboy closed this as completed Aug 19, 2017
@neXyon
Copy link

neXyon commented Aug 19, 2017

Thanks for the example @rubyboy but in your example this in doSomething then is the pickdate object and not the component. How can I get the object of my component class?

@neXyon
Copy link

neXyon commented Aug 21, 2017

Found a solution, in the component:

  dateParams = [{
    // other parameters you want to have
    onSet: () => { this.search(); }
  }]

and then in the template it's as simple as using [materializeParams]="dateParams".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants