如何在角度添加功能

时间:2019-03-19 23:28:38

标签: angular bulma

尝试在Angular中编码基本导航栏,但未执行Angular代码时显示错误TypeError:_co.toggleNavbar不是函数。

<a #navBurger (click)="toggleNavbar()" role="button"  class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
  <span aria-hidden="true"></span>
  <span aria-hidden="true"></span>
  <span aria-hidden="true"></span>
</a>

和我的功能:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
@Component({
  selector: 'app-navigation',
  templateUrl: './navigation.component.html',
  styleUrls: ['./navigation.component.css']
})
export class NavigationComponent  {

  @ViewChild('navBurger') navBurger: ElementRef;
  @ViewChild('navMenu') navMenu: ElementRef;

  constructor() { }

  toggleNavbar() {
    this.navBurger.nativeElement.classList.toggle('is-active');
    this.navMenu.nativeElement.classList.toggle('is-active');
  }
}

0 个答案:

没有答案