代码之家  ›  专栏  ›  技术社区  ›  edkeveked

类型“observable<boolean>”不可分配给类型“observable<breakpointstate>”

  •  2
  • edkeveked  · 技术社区  · 7 年前

    使用角度材质原理图,我想生成导航菜单。为此,我使用以下命令:

    ng generate @angular/material:material-nav --name layout
    

    当我为我的应用程序提供服务时,会引发以下错误:

    错误TS2322:类型“observable”不能分配给类型“observable”。 类型“boolean”不能赋给类型“breakpointstate”。

    2 回复  |  直到 7 年前
        1
  •  3
  •   Lafexlos    7 年前

    添加一个答案,只是为了从未回答的问题中删除这个问题。

    这是一个已知的 issue 和固定 this pull request .

    在这个pr生效之前,您可以手动进行更改。

    __name@dasherize__.component.html

    来自:

    [attr.role]="isHandset$ | async ? 'dialog' : 'navigation'"
    [mode]="isHandset$ | async ? 'over' : 'side'"
    

    到:

    [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
    [mode]="(isHandset$ | async) ? 'over' : 'side'"
    

    __name@dasherize__.component.ts
    

    来自:

    [attr.role]=“ishandset$异步?”对话框“:'导航'”
    [模式]=“Ishandset$Async?”在“:”边上“
    

    到:

    [attr.role]=“(ishandset$async)?”对话框“:'导航'”
    [模式]=“(ishandset$异步)”'在“:”边上“
    

    来自:

    isHandset$: Observable<BreakpointState> = this.breakpointObserver.observe(Breakpoints.Handset)
    

    到:

    isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
    
        2
  •  1
  •   Samarth Saxena    7 年前

    只需在typescript文件中将observable的类型更改为boolean。 匹配组件HTML文件中的括号 [attr.role]=“(ishandset$async)?”对话框“:'导航'” [模式]=“(ishandset$异步)”'在“:”边上“

    这里是绿线

    enter image description here

    这是fix的主要链接- https://github.com/angular/material2/pull/11448/commits/20306dbeed3fe7232ffb85ba1d9fd406f6885db2

    推荐文章