我正在使用Angular 6 使用"rxjs":"^ 6.0.0",
错误:属性'of'在类型'typeof Observable'上不存在.
import { Injectable } from '@angular/core';
import { TranslateLoader } from '@ngx-translate/core';
import { Observable, Subject, pipe, of } from 'rxjs';
@Injectable()
export class MiTranslateLoaderService implements TranslateLoader {
getTranslation(lang: string): Observable<any> {
return Observable.of({
lbl_select: 'Select',
});
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试测试按钮单击是否正在调用正确的方法。当我尝试从 debugElement 获取按钮时,出现以下异常:
TypeError: Cannot read property 'elementMatches' of null
Run Code Online (Sandbox Code Playgroud)
页脚.组件.ts
import { Component } from '@angular/core';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material';
import { FeedbackModalComponent } from './feedback-modal/feedback-modal.component';
import { filter } from 'rxjs/internal/operators';
@Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.css']
})
export class FooterComponent {
dialogRef: MatDialogRef<FeedbackModalComponent>;
constructor(private dialog: MatDialog) {}
openDialog() {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.width = '35%';
dialogConfig.minWidth = '525px';
this.dialogRef = this.dialog.open(FeedbackModalComponent, dialogConfig);
}
} …Run Code Online (Sandbox Code Playgroud) 如何在项目之间共享代码?
我有两个使用以下创建的应用:
ng generate application app1
ng generate application app2
我想projects/app1/src/app.module.ts从中导入一个模块projects/app2/src/shared/common.module.ts
如果没有创建名为common或3rd的第三个项目,最佳做法是什么?创建一个项目/公共或只是common在这里调用一个文件夹并填充TypeScript文件并导入它们.
这是我的代码:
<p-accordion [multiple]="true">
<p-accordionTab header="Godfather I">
The story begins as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war, but does not intend to become part of his father's business. T hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those …Run Code Online (Sandbox Code Playgroud) 我有一个角度的提要服务,它调用一个REST端点,该端点返回EntryDTO列表。服务外观如下:
@Injectable({providedIn: 'root'})
constructor(private http: HttpClient) {}
export class FeedService() {
getPublicFeedEntries: Observable<EntryDTO[]> () {
return this.http.get('/rest/publicFeedEntries/).map((response: Response) => response.json()).catch((err: any) => Observable.throw(error.josn().error || 'error');
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我可以拥有一个订阅此可观察值的提要组件:
export class FeedComponent() {
private feedEntries: EntryDTO[];
constructor(private feedService: FeedService) { feedEntries = new Array(); }
ngOnInit() {
this.feedService.getPublicFeedEntries.subscribe(entries => {
this.feedEntries = entries;
}, err => {console.log(err) })
}
}
Run Code Online (Sandbox Code Playgroud)
这是否被视为在服务中返回可观察对象并订阅组件的最佳实践,还是还有其他最佳实践?
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'push' : 'push'" [opened]="!(isHandset$ | async)">
<mat-toolbar color="primary">Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item href="#">Link 1</a>
<a mat-list-item href="#">Link 2</a>
<a mat-list-item href="#">Link 3</a>
</mat-nav-list>
</mat-sidenav>
Run Code Online (Sandbox Code Playgroud)
我不明白代码中写的是什么,(isHandset$ | async)请解释一下
如何使用routerLinkActive点击事件和不使用routerLink?我在某处读到,同时使用 click 和 routerLink 并不是一个好的做法。我想在单击链接时设置一个活动类,并希望在将用户导航到单击的页面之前对单击事件执行一些业务功能。下面的代码没有设置类。
<button
type="button"
class="list-group-item list-group-item-action"
routerLinkActive="active"
*ngFor="let service of services"
(click)="changeService(service)">
{{ service | titlecase }}
</button>
Run Code Online (Sandbox Code Playgroud) 在 Angular 6 中,当我们创建一个组件时,该组件的 .ts 文件有一个实现 OnInit 类的类,但是当我们删除默认方法(ngOnInit)时,它可以正常工作。所以我的问题是,如果它实现了某个类,那么它必须有一些必须在这个实现的类中实现的方法,如果不需要有方法,那么实现 OnInit 类的目的是什么。
我正在使用 angular/rxjs6 构建一个简单的秒表,我可以启动计时器,但无法暂停/恢复它。
source: Observable<number>;
subscribe: Subscription;
start() {
this.source = timer(0, 1000);
this.subscribe = this.source
.subscribe(number => {
this.toSeconds = number % 60;
this.toMinutes = Math.floor(number / 60);
this.toHours = Math.floor(number / (60 * 60));
this.seconds = (this.toSeconds < 10 ? '0' : '') + this.toSeconds;
this.minutes = (this.toMinutes < 10 ? '0' : '') + this.toMinutes;
this.hours = (this.toHours < 10 ? '0' : '') + this.toHours;
});
}
pause() {
this.subscribe.unsubscribe(); // not working
}
Run Code Online (Sandbox Code Playgroud)
经过大量搜索后,我发现我应该使用switchMap …
我有一个 angular6 应用程序,我们只支持 chrome,但我希望出现一个页面/消息,显示用户尝试在 IE 中导航到该应用程序,说它不受支持,将此链接粘贴到 chrome 中或下载 chrome .
我是否需要一个 polyfill 来使应用程序能够在 IE 上运行以显示此消息,或者是否有某种浏览器检测我可以使用仅显示此弹出窗口?
我知道您可以在 TS 中进行浏览器检测,我有,但这意味着我需要一个 IE polyfill,以便应用程序加载以显示页面。
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+ …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×6
rxjs6 ×2
browser ×1
css ×1
jasmine ×1
javascript ×1
karma-runner ×1
mat-sidenav ×1
oop ×1
primeng ×1
rxjs ×1
sidenav ×1
typescript ×1