小编Ric*_*cha的帖子

Angular 2+:检查dom元素是否是另一个dom元素的子元素

我有以下代码:

import { Component, OnInit, OnDestroy } from "@angular/core";

@Component({
  selector: 'sidebar-component',
  templateUrl: './sidebar.component.html'
})

export class SideBarComponent implements OnInit, OnDestroy {

  constructor() {}

  ngOnInit(): void {
      window["isSideBarElement"] = this.isSideBarElement;
  }

  ngOnDestroy(): void {}

  private isSideBarElement(event): boolean{
    let element: HTMLElement = event.target as HTMLElement;
    //mising code check if the target of the event is a child of the component
  }

  private getDOMElement(): HTMLElement{
    return document.getElementsByTagName("sidebar-component")[0] as HTMLElement;
  }

}
Run Code Online (Sandbox Code Playgroud)

在函数中,isSideBarElement我想检查事件的目标是否是组件的子级。

有任何建议吗?

typescript angular

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

Angular: 类 HttpParams 上的解释参数类型 [param: string]: string | 细绳[];

我使用的 HttpParams 是以下构造函数:

constructor(options?: {
        fromString?: string | undefined;
        fromObject?: {
            [param: string]: string | string[];
        } | undefined;
        encoder?: HttpParameterCodec | undefined;
});
Run Code Online (Sandbox Code Playgroud)

任何人都可以向我解释 fromObject 参数的含义以及如何使用它?

romObject?: {
     [param: string]: string | string[];
} | undefined;
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

错误:输入'[数字] | [数字,数字,数字,数字]'不可分配给类型'[数字]'

从 angular 5.1 更新到 6.1 后,我开始从我的代码中收到一些错误,如下所示:

错误:ngc 编译失败:components/forms/utils.ts(5,3):错误 TS2322:类型 '[number] | [编号,编号,编号,编号]' 不可分配给类型 '[编号]'。

遵循以下代码:

export function bsColumnClass(sizes: [number]) {

  let sizebs = ['col-xs-', 'col-sm-', 'col-md-', 'col-lg-',];

  sizes = sizes || [12, 12, 12, 12];

  let className = sizes.map(function callback(value, index, array) {
    return sizebs[index].concat(value.toString());
  }).join(" ");

  return className;
}
Run Code Online (Sandbox Code Playgroud)

我注意到问题是因为我有一个函数参数sizes: [number],然后我正在训练执行这行代码:sizes = sizes || [12, 12, 12, 12];

你能告诉我解决这个问题的更好方法吗?

typescript angular

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

"object is null"表达式给出错误

我有以下代码:

public static class ItemsHelper
{
    public static object product
    {
        get
        {
            return HttpContext.Current.Items["product"];
        }
        set
        {
            HttpContext.Current.Items["product"] = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后,在函数中,我有以下表达式:

if (ItemsHelper.product is null) return false;
Run Code Online (Sandbox Code Playgroud)

我在视觉工作室2017测试,它工作正常,但我测试了运行visual studio 2015的两台不同的计算机,它检索到以下错误:

预期类型)

任何人都知道为什么会这样?

c# visual-studio-2015 c#-7.0 visual-studio-2017

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

RxJS6(角度6)-node_modules / rxjs / Rx.d.ts(1,15)中的错误:错误TS2307:找不到模块“ rxjs-compat”

我最近将应用程序更新为angular 6,将RxJs更新为6.3.3 version

如描述在这里,我使用的包rxjs-compat有暂时写入RxJS5和RxJS6兼容模式的代码,在相同的时间。

正如RxJS团队所建议的那样,在更新所有代码以使其与RxJS6兼容之后,我将rxjs-compat其卸载了,因为不再需要它了。

在那之后,我试图运行我的代码,但是编译器正在检索以下错误:

node_modules / rxjs / Rx.d.ts(1,15)中的错误:错误TS2307:找不到模块“ rxjs-compat”

有人知道这里可能有什么问题吗?这似乎取决于RxJS的方式rxjs-compat,但是如果我说的是真的,为什么RxJS团队建议卸载rxjs-compat

rxjs rxjs5 angular rxjs6

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

找不到模块:错误:无法解析“ C:\ dev \ jszip-test \ node_modules \ jszip \ lib”中的“流”

jszip v3.2.1在angular 7应用程序中使用。当我构建项目(例如正在运行)时,npm start出现以下错误:

./node_modules/jszip/lib/visible-stream-browser.js中的错误

找不到模块:错误:无法解析“ C:\ dev \ jszip-test \ node_modules \ jszip \ lib”中的“流”

我怎么解决这个问题?

javascript npm typescript jszip angular

1
推荐指数
4
解决办法
2151
查看次数

弃用消息:“从‘进程’(属性)NodeJS.Process.mainModule 自动导入?:NodeJS.Module NodeJS.Module‘mainModule’已弃用”

我正在尝试像这样使用 mainModule:

const { mainModule } = require('process');
module.exports = path.dirname(mainModule.filename);
Run Code Online (Sandbox Code Playgroud)

但我收到以下消息:

const mainModule:NodeJS.Module 'mainModule' 已弃用(6385)

从“进程”(属性)NodeJS.Process.mainModule 自动导入?:NodeJS.Module

@deprecated — 从 v14.0.0 开始 — 改用 require.main。

我该如何解决这个问题?

javascript node.js

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

切片似乎不适用于函数数组

我有这个功能:

function UIAlerts() {}
Run Code Online (Sandbox Code Playgroud)

然后我使用原型方法将变量关联到此函数中:

UIAlerts.prototype.questions = []
Run Code Online (Sandbox Code Playgroud)

之后,我将一个函数推送到这个数组:

UIAlerts.prototype.questions.push(function(){
     //do stuff
});
Run Code Online (Sandbox Code Playgroud)

执行单击事件后,执行以下代码:

if (UIAlerts.prototype.questions && UIAlerts.prototype.questions.length > 0) {
        UIAlerts.prototype.questions.slice(0, 1);
        UIAlerts.prototype.questions[0] && UIAlerts.prototype.questions[0]();
}

if (UIAlerts.prototype.questions.length == 0)
    UIAlerts.prototype.questions = undefined;
Run Code Online (Sandbox Code Playgroud)

问题是切片不会删除函数数组的第一个possion.任何的想法?

javascript arrays

0
推荐指数
1
解决办法
38
查看次数