我正在使用 Angular Material 选项卡组。
<mat-tab-group>
<mat-tab label="First"> <app-home> </app-home> </mat-tab>
<mat-tab label="Second"> <app-info> </app-info> </mat-tab>
<mat-tab label="Third"><app-details> </app-home> </mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)
在ngOnInit(){}每个组件中,我正在调用一个或多个 API,以及当我的应用程序组件呈现选项卡组时。所有选项卡的内容都被异步加载,为此,所有组件的所有 API 都被调用。这是在降低效率。
我想控制选项卡内容的呈现,以便仅呈现选定的选项卡。这样我就可以阻止所有其他 API 被不必要地调用。
任何人都可以通过指导适当的事件或技术来帮助我实现这一目标吗?
我们有以下路由场景:
export const ROUTES: Routes = [
{
path: ':userId',
component: fromContainers.OrganizationComponent,
canActivate: [],
children: [
{ path: '', pathMatch: 'full', redirectTo: 'posts' },
{
path: 'posts',
loadChildren: './views/posts/posts.module#PostsModule'
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
我们的路由器存储无法识别userId这种方式,但是当我们删除该children属性时,它确实识别了 的值userId。
http://localhost:4200/user/r1RORssFG --> WORKS
http://localhost:4200/user/r1RORssFG/posts --> DOES NOT WORK
Run Code Online (Sandbox Code Playgroud)
这种行为背后的原因是什么?
我在我的 Angular 应用程序 ( https://danielykpan.github.io/date-time-picker/ ) 中使用 NgPickDatetime,当我尝试翻译标签和消息时遇到问题。我按照文档中的说明操作,它工作正常,但问题是当我更改站点语言时,标签仍然使用以前的语言。
我的代码是:
日期时间-locale.module.ts:
import { NgModule } from '@angular/core';
import { OwlDateTimeModule, OwlNativeDateTimeModule, OwlDateTimeIntl} from 'ng-pick-datetime';
import { DefaultIntl } from './datepicker-locale.component';
@NgModule({
imports: [OwlDateTimeModule, OwlNativeDateTimeModule],
providers: [
{provide: OwlDateTimeIntl, useClass: DefaultIntl},
],
})
export class DateTimeLocaleModule {
}
Run Code Online (Sandbox Code Playgroud)
datepicker-locale.component.ts:
import { OwlDateTimeIntl } from 'ng-pick-datetime';
export class DefaultIntl extends OwlDateTimeIntl {
public cancelBtnLabel = 'Annuleren';
public setBtnLabel = 'Opslaan';
private currentLang;
constructor() {
super();
this.getLang();
}
public getLang() {
this.currentLang = JSON.parse(localStorage.getItem("language")); …Run Code Online (Sandbox Code Playgroud) 我是一个使用 angular6 的 webrtc 的新手。当我研究 WebRTC API 并构建一个简单的页面以在本地测试中显示/停止网络摄像头流时。我在开发中收到一条错误消息。有我的开发环境:
Angular 6.1.0
Angular-cli 6.1.2
打字稿 2.9.2
我构建了“停止”按钮来执行函数 stopBtn()。但是打字稿编译器会在构建应用程序时抛出错误消息:
错误 TS2339:属性“getTracks”不存在于类型“MediaStream | 斑点| 媒体资源”。“Blob”类型上不存在属性“getTracks”。
stopBtn() 函数代码:
private video: HTMLVideoElement;
.......
ngOnInit() {
this.video = <HTMLVideoElement>this.el.nativeElement.querySelector('#video');
}
........
getDevice() {.....}
getStream() {.....}
gotStream() {.....}
.......
stopBtn() {
if (this.video.srcObject) {
this.video.srcObject.getTracks().forEach( stream => stream.stop());
this.video.srcObject = null;
}
}
Run Code Online (Sandbox Code Playgroud)
html简单代码:
<video id="video" autoplay></video>
<button id="stopbtn" type="button" (click)="stopBtn()">Stop</button>
Run Code Online (Sandbox Code Playgroud)
此页面可以正确显示流。
我已经通过 stackoverflow 或 google 搜索了许多关键字来查找此错误消息。但是没有得到任何好的答案。所以希望有人能帮我解决。谢谢你。
我正在循环我的数据列表并在视图中显示,作为 spans 标签:
<span *ngFor="let d of myData; last as isLast">
{{d.name}}
<span *ngIf="!isLast">,</span>
</span>
Run Code Online (Sandbox Code Playgroud)
如您所见,我添加了一个逗号 '**, betewen items values
这看起来像这样 ::
AAA,BBB,CCC,DDD,
Run Code Online (Sandbox Code Playgroud)
但碰巧我的数据是空的:所以我想显示一些自定义字符串: "NO ITEMS"
我想在 html 部分用管道处理它
建议?
我正在使用反应式文本框,我需要一些自定义验证。
输入框不能有以空格开头的字符。
我正在使用所需的验证器使其成为强制性的,但如果我输入一个空格,它仍然认为它有效(我不想要)。
我怎样才能解决这个问题?
如何改变 mat-spinner 的颜色我试过了,但不起作用
html
<mat-spinner [color]="red" ></mat-spinner>
<mat-spinner [color]="#ffffff" ></mat-spinner>
Run Code Online (Sandbox Code Playgroud) 尝试从 5 升级到 Angular 6 并收到此错误:
src/app/app.component.ts(26,23) 中的错误:错误 TS2339:“Observable”类型上不存在“distinctUntilChanged”属性。
我在 app.module.ts 中导入了 distinctUntilChanged:
import "rxjs/add/operator/distinctUntilChanged";
Run Code Online (Sandbox Code Playgroud)
我在 app.component.ts 中的代码:
import { Component } from "@angular/core"; import { Router, NavigationEnd } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { GeoService } from "app/services/geo.service";
import { ArbeteService } from "app/services/arbete.service";
import { GoogleAnalyticsEventsService } from "app/services/google-analytics-events.service";
import * as _ from "lodash";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
})
export class AppComponent {
//Send pageview to Google Analytics
router.events.distinctUntilChanged((previous: any, …Run Code Online (Sandbox Code Playgroud) 我需要将页面上当前显示的数据导出为 excel 或 pdf。那么我怎么能得到只显示在页面上的数据。我将整个数据存储在数据源对象中。例如:- 如果每页的项目是 10 ,我需要 10 项目。如果我将分页器项目列表更改为 20,那么我需要 20 个项目。
组件 HTML
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8 mat_datatable" matSort matSortActive="total_click" matSortDirection="desc" multiTemplateDataRows matSortDisableClear>
Run Code Online (Sandbox Code Playgroud)
组件.ts
import {MatPaginator, MatSort, MatTableDataSource} from
'@angular/material';
this.dataSource = new MatTableDataSource(this.reports);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
Run Code Online (Sandbox Code Playgroud)
这是我的组件文件。
我正在使用引导模式,但是当我从代码隐藏中隐藏它时,它会显示以下错误。
我正在使用 angular6。
代码
<div #exampleModal class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
@ViewChild('exampleModal') public exampleModal: ElementRef;
this.exampleModal.hide();
Run Code Online (Sandbox Code Playgroud)
错误信息
错误类型错误:this.exampleModal.hide 不是函数
angular6 ×10
angular ×9
angular5 ×4
javascript ×3
datatable ×1
ngrx ×1
ngrx-store ×1
pagination ×1
rxjs5 ×1
rxjs6 ×1
typescript ×1
webrtc ×1