小编mig*_*ton的帖子

找不到模块:错误:无法解析“fs”

好吧,我将 Angular 从 6 升级到了 8。但我仍然遇到错误。

我在互联网上找到了一个对很多用户都有帮助的解决方案。但在这种情况下,它对我没有帮助。

所以我的 package.json 文件看起来像这样:

{
  "name": "vital10-frontend",
  "version": "0.55.0",
  "license": "Unlicensed",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "hmr": "ng serve --configuration hmr",
    "build": "ng build",
    "build:prod": "npm run sass:prod && npm run vit10prod",
    "build:acc": "npm run sass:prod && npm run vit10acc",
    "build:test": "npm run sass:prod && npm run vit10test",
    "build:dev": "npm run sass:prod && npm run vit10dev",
    "test": "ng test",
    "test:cover": "ng test --code-coverage",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "local": "ng serve …
Run Code Online (Sandbox Code Playgroud)

javascript angular

49
推荐指数
6
解决办法
10万
查看次数

如何通过点击事件与父子组件进行通信

我有一个 Angular 8 应用程序。我有父母和孩子的关系。

所以我在父 DossierCorrespondenceComponent 中有一个函数,但该函数必须在子组件中触发。

所以我在父级中有这个函数:

@Input()  myGotoItem: Function;


gotoItem(index, type: string) {
    this.showingSingle = true;

    switch (type) {
      case 'correspondence': {
        this.single = this.correspondenceEntries[index];
        break;
      }
      case 'attachments': {
        this.single = this.attachmentEntries[index];
        break;
      }
      default: {
        break;
      }
    }
    this.showingSingle = true;
  }

Run Code Online (Sandbox Code Playgroud)

我尝试在子组件 DossierCorrespondenceListComponent 中调用它,如下所示:

@Input()  myGotoItem: Function;


gotoItem(index, type: string) {
    this.showingSingle = true;

    switch (type) {
      case 'correspondence': {
        this.single = this.correspondenceEntries[index];
        break;
      }
      case 'attachments': {
        this.single = this.attachmentEntries[index];
        break;
      }
      default: { …
Run Code Online (Sandbox Code Playgroud)

function dom-events typescript angular

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

类型“ Observable <未知>”不可分配给类型“ Observable <Lesson []>”

我正在使用Angular 8应用程序。我正在使用可观察模式形式rxjs。但是我仍然在Observable线上遇到错误。

搜索错误,当然。但是没有找到正确的答案。

所以我导入了这个:

import { Subject, Observer, Observable } from 'rxjs';
Run Code Online (Sandbox Code Playgroud)

我有这条线:

    public lessonList$: Observable<Lesson[]> = this.lessonListSubject.asObservable();
Run Code Online (Sandbox Code Playgroud)

但我仍然收到此错误:


Type 'Observable<unknown>' is not assignable to type 'Observable<Lesson[]>'.
  Type '{}' is missing the following properties from type 'Lesson[]': length, pop, push, concat, and 26 more.ts(2322)
Run Code Online (Sandbox Code Playgroud)

该错误将消失。

谢谢

oke,这是界面课程:

export interface Lesson {
    id: number;
    description: string;
    duration?: string;
    completed?: boolean;

}
Run Code Online (Sandbox Code Playgroud)

这是整个文件:

import * as _ from 'lodash';
import { Lesson } from '../shared/model/lesson';
import { Subject, Observer, Observable } from …
Run Code Online (Sandbox Code Playgroud)

observable rxjs angular

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

函数中绝对数的和

我试试这个:

public static int sum(List<int> list)
{
        int sum = 0;

        foreach (var item in list)
        {
            sum = item + sum;
        }

        return sum;
}

public static int sumAbsolute(List<int> list)
{
        foreach (var item in list)
        {
            Math.Abs(item);
        }          

        return sum(list); 
}
Run Code Online (Sandbox Code Playgroud)

以及主函数中的:

static void Main(string[] args)
{          
        var list = new List<int>() {
            -1,-2,-3
        }; 

        Console.WriteLine(sumAbsolute(list));
        Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)

但输出是-6而不是6。

那么为什么我的代码不起作用呢?

c#

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

不支持关键字:trusted_connection(参数“关键字”)

我有一个 .NET Core 应用程序。通常我只需使用dotnet watch run.

但显然有些事情发生了变化。因为如果我现在这样做dotnet run watch,我会收到此错误:

API.Program[0]
迁移期间发生错误

System.ArgumentException:不支持关键字:trusted_connection(参数“关键字”)

在 Npgsql.NpgsqlConnectionStringBuilder.GetProperty(字符串关键字)
在 Npgsql.NpgsqlConnectionStringBuilder.set_Item(字符串关键字,对象值)
在 System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(字符串值)
在 Npgsql.NpgsqlConnectionStringBuilder..ctor(字符串连接字符串)
在 Npgsql .EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.ExistsAsync(CancellationToken CancellationToken)
在 Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.ExistsAsync(CancellationToken CancellationToken)
在 Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken CancellationToken)
在E:\Mijn Documents\UDEMY\C#\Reactivities-main\api\Program.cs 中的 API.Program.Main(String[] args):第 28 行

所以我检查了我的appsettings.development.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=DESKTOP-EIC4DNM; Initial Catalog=reactivities;Trusted_Connection=true;"
  },

  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Information",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "TokenKey": "super secret key"
}
Run Code Online (Sandbox Code Playgroud)

和我的程序:

public class Program
{
    public static async Task …
Run Code Online (Sandbox Code Playgroud)

c# connection-string .net-core

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

如何使用列表理解比较两个字典的值?

如何仅比较两个字典的值?

所以我有这个:

dict1 = {"appe": 3962.00, "waspeen": 3304.08}
dic2 = {"appel": 3962.00, "waspeen": 3304.08}


def compare_value_dict(dic):
    return dic

def compare_value_dict2(dic2):   
    return dic2
    

def compare_dic(dic1, dic2):
    if dic1 == dic2:       
        print('the same dictionary')
    else:      
        print('difference dictionary')

compare_dic(compare_value_dict(dict1).values(), compare_value_dict2(dic2.values()))

Run Code Online (Sandbox Code Playgroud)

这有效:

compare_dic(compare_value_dict(dict1).keys(), compare_value_dict2(dic2.keys()))
Run Code Online (Sandbox Code Playgroud)

python dictionary dictview

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

类型“ArrayBuffer”上不存在属性“substring”。ts(2339)

我将 Angular 6 更新为 Angular 8。一切似乎都正常。除了一件事。

我用谷歌搜索了这个:属性“substring”在类型“ArrayBuffer”.ts(2339)上不存在。但没有得到满意的答复

所以我有这个:

 const base64Img = fileReader.result.substring( fileReader.result.indexOf( ',' ) + 1 );
Run Code Online (Sandbox Code Playgroud)

结果属性如下所示:

readonly result: string | ArrayBuffer | null;
Run Code Online (Sandbox Code Playgroud)

但现在我得到这个错误:

Property 'substring' does not exist on type 'string | ArrayBuffer'.
  Property 'substring' does not exist on type 'ArrayBuffer'.ts(2339)
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:如何解决这个问题?

谢谢

你不会再遇到编译器错误

整个函数如下所示:

 loadImage( event: Event ) {
    const fileInput = event.target as HTMLInputElement;
    this.selectedFileName = fileInput.files[ 0 ].name;
    if ( fileInput.files[ 0 ] ) {
      const fileReader = new FileReader();
      fileReader.addEventListener( 'load', () …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

如何在一个功能中组合切换功能?

我有一个显示/隐藏图像的切换功能。但我现在有两个功能。他们几乎做同样的事情。

所以我的问题是,如何将它们组合成一个功能?

所以我有这样的模板:

<div *ngIf="!isShowWifi">
    <mgl-image id="wifi" url="./assets/radar.png" (loaded)="imageLoaded = true">
    </mgl-image>
  </div>

  <div *ngIf="!isShowCamera">
    <mgl-image
      id="camera"
      url="./assets/noun_Camera.png"
      (loaded)="imageLoaded = true"
    >
    </mgl-image>
  </div>

Run Code Online (Sandbox Code Playgroud)

和按钮:

<div class="menu">
  <mat-button-toggle [checked]="true" (click)="this.toggleDisplayDivIfCamera()">camera</mat-button-toggle>
  <mat-button-toggle [checked]="true" (click)="this.toggleDisplayDivIfWifi()">wifi</mat-button-toggle>
</div>
Run Code Online (Sandbox Code Playgroud)

和 ts 脚本:

 isShowCamera = false;
  isShowWifi = false;

  toggleDisplayDivIfWifi() {
    this.isShowWifi = !this.isShowWifi;
  }

  toggleDisplayDivIfCamera() {
    this.isShowCamera = !this.isShowCamera;
  }

Run Code Online (Sandbox Code Playgroud)

那么如何在一个函数中编写它呢?

谢谢

html javascript typescript angular

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