"Click" does not work in angle

0

Follow the codes. While hiding the menu, it does not re-open with the "click" function in nav-burger

menu.component:

section class="hero outer is-primary is-fullheight animated slideInLeft" [ngClass]="{'is-hidden' : !menu.opened}">

menu.service.ts:

@Injectable()
export class MenuService {
  opened: boolean;

  constructor() { }
  open (){
    this.opened = true;
  }

}

header.component.ts:

@Component({
  providers: [MenuService],
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.sass']
})
export class HeaderComponent implements OnInit {

  constructor(public menu:MenuService) { 

header html:

 <div class="navbar-burger burger" (click)="menu.open()">
      <span></span>
      <span></span>
      <span></span>
    </div>
    
asked by anonymous 17.02.2018 / 01:36

1 answer

1

You have to have the function in the component

header.component.ts

@Component({
  providers: [MenuService],
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.sass']
})
export class HeaderComponent implements OnInit {

  constructor(public menu:MenuService) { }

 openMenu(){
   this.menu.open()
  }
}

And no html:

 <div class="navbar-burger burger" (click)="openMenu()">
    
21.02.2018 / 17:11