小编Col*_*rus的帖子

TypeScript:对象相等比较(对象等于对象)

我找到了这个(个人)方便的答案,满足我的需求: /sf/answers/469964771/

但由于我使用的是TypeScript ,所以我可以使用Generics来实现类似的功能:

private equals<T>(x: T, y: T) {
    if (x === y) {
        return true; // if both x and y are null or undefined and exactly the same
    } else if (!(x instanceof Object) || !(y instanceof Object)) {
        return false; // if they are not strictly equal, they both need to be Objects
    } else if (x.constructor !== y.constructor) {
        // they must have the exact same prototype chain, the closest we can …
Run Code Online (Sandbox Code Playgroud)

optimization compare equality typescript ecmascript-6

6
推荐指数
1
解决办法
2万
查看次数

使用在线构建生成器时,CKEditor5 工具栏未显示在 Angular 中

我正在使用从在线构建生成器生成的自定义构建。

然后我按照用Angular 的富文本编辑器组件编写的文档进行操作,但使用自定义构建而不是使用官方编辑器构建之一

不知何故,我的工具栏及其图像工具栏和表格工具栏等项目没有显示在我的 Angular 项目中。Executingnpm install提供了工具栏所需的文件,以"image"在在线构建示例页面上显示完整的项目(包括等)。

我在这里缺少什么才能成功显示使用在线构建生成器定义的工具栏及其项目?

ckeditor5

6
推荐指数
1
解决办法
1388
查看次数

如何防止在确认之前更改 MatTab?

我想保留更改MatTab直到得到确认。我已经用来MatDialog确认了。问题是,在单击“是”之前,选项卡已更改。

例如,在收入选项卡中,我单击调整选项卡。在切换到该选项卡之前,我需要先显示弹出窗口。但我在移动到调整选项卡后收到弹出窗口。

显示弹出窗口的图像

组件模板:

 <mat-tab-group (click)="tabClick($event)">
  <mat-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
    <app-spread></app-spread
  </mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)

组件ts(onClick的方法):

tabClick(clickEvent: any) {
    if (clickEvent.target.innerText != 'First') {
      this.confirm();
    }
  }
  public async confirm() {
    const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
      maxHeight: '200px',
      maxWidth: '767px',
      width: '360px',
      disableClose: true,
      data: {
        title: 'Confirmation Message',
        content:
          'There are valid statements that are not Final. Set the statements as Final?'
      } …
Run Code Online (Sandbox Code Playgroud)

typescript angular-material angular mat-tab

6
推荐指数
1
解决办法
5081
查看次数

如何为从组件导入的模块设置config(或useValue)?

我们很清楚,有多种方法可以为导入的模块设置config。我们有“ .forRoot()”,“ useValue”,“ useClass”,这些将在导入模块中使用。

例如,我们要使用ng2-currency-mask。直接从文档中的示例用法中,我们可以CurrencyMaskModule通过在导入模块(在本例中为AppModule)中进行设置来进行配置:

export const CustomCurrencyMaskConfig: CurrencyMaskConfig = {
    align: "right",
    allowNegative: true,
    decimal: ",",
    precision: 2,
    prefix: "Module$ ",
    suffix: "",
    thousands: "."
};

@NgModule({
    imports: [
        ...
        CurrencyMaskModule
    ],
    declarations: [...],
    providers: [
        { provide: CURRENCY_MASK_CONFIG, useValue: CustomCurrencyMaskConfig }
    ],
    bootstrap: [AppComponent]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)

但是,如果要useValue动态设置config / (例如,“设置”页面),则必须在组件内部进行更改。现在,我使用以下直接在中编写的代码进行了测试AppComponent

import { Component, OnInit, Inject } from '@angular/core';
import { CURRENCY_MASK_CONFIG, CurrencyMaskConfig } from 'ng2-currency-mask/src/currency-mask.config';

@Component({
  selector: 'app-root', …
Run Code Online (Sandbox Code Playgroud)

dependency-injection typescript angular-module angular angular-dependency-injection

5
推荐指数
0
解决办法
406
查看次数

3
推荐指数
1
解决办法
1637
查看次数