问题描述
我正在尝试使用ObservableMedia.应用程序编译成功,但是在浏览器控制台中我看到此错误
I am trying to user ObservableMedia. Application compiles successfully but in browser console i see this error
这是我的密码
import { Component , OnInit, ViewChild} from '@angular/core';
import {Observable} from 'rxjs/Rx';
import {MediaChange, ObservableMedia} from "@angular/flex-layout";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
constructor(
public media: ObservableMedia) {
}
routeLinkClick() {
if (!this.media.isActive('gt-xs')) {
this.sidenav.toggle();
}
}
请帮助.谢谢
推荐答案
在Flex-layout版本7.0.0-beta.20及更高版本中,ObservableMedia被MediaObserver取代.
In flex-layout versions 7.0.0-beta.20 and higher ObservableMedia was replaced with MediaObserver.
media-observer:现在已弃用ObservableMedia,因为它已预期RxJS v7.新的API称为MediaObserver,它提供与ObservableMedia完全相同的功能,只是您不能直接订阅它,
开发人员应订阅MediaObserver的media $属性;代替直接订阅ObservableMedia. -引用自 https://github.com/angular/flex-layout/blob/master/CHANGELOG.md
Developers should subscribe to MediaObserver's media$ property; in place of subscribing directly to ObservableMedia.- quoted from https://github.com/angular/flex-layout/blob/master/CHANGELOG.md
进行了此更改之后,它在今天的最新版本上没有任何问题:
After I made that change, it worked with no issues on the latest versions as of today:
这篇关于角度错误:没有ObservableMedia的提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!