Bahadur Singh Deol
Bahadur Singh Deol

Reputation: 821

How can I write and use all click event in one file and use another component Angular 5

My my-company.component.html

<a id="menu" (click) ="menuClick()" class="vcal-btn h100"><span>Dashboard</span></a>

My another component file company-jquery.ts

import { Injectable } from '@angular/core';

import * as $ from "jquery";


@Injectable()
export class CompanyJquery {
    constructor() {
        this.load();
    }

    menuClick(){
        $('#sidebar-left').addClass('ls-open');
        $(".dis-container").addClass("dis-width");
        $(".device-sec").addClass("dev-width");
        $('#sidebar-left .sidebar-btn').addClass('ls-open')
        $(this).addClass('none')
    }
}

my my-company.component.ts

import { CompanyJquery } from '../_directives/company-jquery';
    export class MyCompanyComponent implements OnInit {

      constructor(
       private companyJquery: CompanyJquery,
       ) { }

      ngOnInit() {
        this.companyJquery.menuClick();
      }
    }

How can I store all click event in one file and excess in all component base on method Above concept doesn't work.

Upvotes: 0

Views: 41

Answers (1)

Oleksii Pavlenko
Oleksii Pavlenko

Reputation: 1333

I think the best approach is to use @ngrx/store, it solve all yours problems.

more details on @ngrx/store

On basic example describes yours case

Upvotes: 1

Related Questions