我正在建立一个侧面导航在Angular 使用material 侧面导航.但当我绑定[(模式)]时,它总是抛出错误:

The property and event halves of the two-way binding 'mode' are not bound to the same target.

Find more at 100

index.d.ts(14, 8): The property half of the binding is to the 'MatSidenav' component.

layout.component.ts(5, 6): The event half of the binding is to a native event called 'mode' on the DOM element.

Are you missing an output declaration called 'modeChange'?

我的html:

<div class="layout-container">
  <app-top-nav (sideNavToggled)="snav.toggle()"></app-top-nav>

  <mat-sidenav-container class="sidenav-container" [style.marginTop.px]="toolBarHeight">
    <mat-sidenav #snav class="sidenav mat-elevation-z10" [(opened)]="sideNavOpened" [(mode)]="sideNavMode" >
      <app-side-nav></app-side-nav>
    </mat-sidenav>
    <mat-sidenav-content>
      <main class="main-container">
        <router-outlet></router-outlet>
      </main>
    </mat-sidenav-content>
  </mat-sidenav-container>
</div>

我的TS:

import { Component, OnInit, OnDestroy } from '@angular/core';
import { MediaObserver, MediaChange } from '@angular/flex-layout';
import Input from '@material-ui/core/Input';
import { Subscription, map } from 'rxjs';

@Component({
  selector: 'app-layout',
  templateUrl: './layout.component.html',
  styleUrls: ['./layout.component.scss'],
})
export class LayoutComponent implements OnInit, OnDestroy {
  sideNavOpened = true;
  sideNavMode: 'side' | 'over' = 'side';
  toolBarHeight = 64;
  private readonly mediaWatcher: Subscription;
  constructor(media: MediaObserver) {
    this.mediaWatcher = media
      .asObservable()
      .pipe(map((changes: MediaChange[]) => changes[0]))
      .subscribe((change: MediaChange) => {
        if (change.mqAlias === 'sm' || change.mqAlias === 'xs') {
          if (this.sideNavOpened) {
            this.sideNavOpened = false;
          }
          this.sideNavMode = 'over';
        } else {
          this.sideNavOpened = true;
          this.sideNavMode = 'side';
        }
        if (change.mqAlias === 'xs') {
          this.toolBarHeight = 56;
        } else {
          this.toolBarHeight = 64;
        }
      });
  }
  ngOnInit() {}

  ngOnDestroy(): void {
    this.mediaWatcher.unsubscribe();
  }
}

我不知道该怎么解决这个问题.请帮帮我.非常感谢.

推荐答案

use mode in this way

[模式]="侧导航模式"

Angular相关问答推荐

如何从Angular TS文件传递$Events对象?

自动完成搜索过滤器不适用于Angular 中动态添加的输入字段

如何在HTML外部项目中使用Web组件(以17角创建)

从、管道和映射可观察到的逻辑?

在剑道UI网格中包装Excel导出的列

具有多个输入的Angular struct 指令在第一次加载构件时没有值

如何使用来自不同可观测对象的值更新可观测对象

如何在Angular功能路由保护中取消订阅RxJs主题

使用 primeng Apollo 主题进行实时部署时多次加载 theme.css 和 preloading.css 文件

Angular 信号 在 effect() 中使用 debounce

Angular APP_INITIALIZER 中的 MSAL 身份验证

如何以Angular 改变环境

如何在插值中编写条件?

Angular2 Pipes:输出原始 HTML

Electron - 不允许加载本地资源

Angularmaterial步进器:禁用标题导航

如何在 Angular 6 中使用 mouseover 和 mouseout

Angular 5 中 value 和 ngValue 的区别

如何在Angular中使用带有 td 属性 colspan 的属性绑定?

'ng' 不是内部或外部命令、可运行程序或批处理文件