L
L
Leopandro2018-07-17 21:23:56
Angular
Leopandro, 2018-07-17 21:23:56

How to call a component function from another?

Hello, I have one problem - I don't know how to call the component's function, just like I call the $('#modal_ask').modal();
Here is the component:

import {Component, OnInit, Input, OnChanges, SimpleChanges} from '@angular/core';

declare var $: any;

@Component({
    selector: 'app-terminal-modal',
    templateUrl: './terminal-modal.component.html',
    styleUrls: ['./terminal-modal.component.css']
})
export class TerminalModalComponent implements OnChanges, OnInit {
    @Input() model: any;
    @Input() wtf: any;
    id: any = '#profile';

    constructor() {
    }

    ngOnInit() {
        console.log(this.model);
    }

    modalReviewsText() {
        $('#modal_ask').modal();
    }

    ngOnChanges(changes: SimpleChanges) {
        console.log(this.model);
        if (this.model)
            this.showModal();
    }

    showModal() {
        console.log(this.id);
        $(this.id).modal();
    }

    hideModal() {
        console.log(this.id);
        $(this.id).modal('hide');
    }
}

This is in the parent controller:
<app-terminal-modal
                            [wtf]="time"
                            [model]="parking"
                    ></app-terminal-modal>

I have to open the modal by changing the value of the input, how can I call the function
showModal() {
        console.log(this.id);
        $(this.id).modal();
    }
directly as a function?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question