小编Mun*_*kin的帖子

从 Angular 8 更新到 9 时位置 0 处的值

我正在按照 update.angular.io 上的更新指南(+ 运行 npm update)将我的项目从 Angular 8 更新到 9 并尝试使用ng serve我编译网站时出现以下错误:

ERROR in Failed to compile entry-point angular-font-awesome (es2015 as esm2015) due to compilation errors:
node_modules/angular-font-awesome/dist/angular-font-awesome.js:3968:26 - error NG1010: Value at position 0 in the NgModule.imports of AngularFontAwesomeModule is not a reference: [object Object]

3968                 imports: [CommonModule],

Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。

更新

我的ng version输出:

   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / ? \ | '_ \ …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular-ivy

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

.NET 6(稳定)Program.cs 中的 IConfiguration 设置

这似乎是一个类似的问题,但没有一个答案适合我的代码...:阅读 Main Program.cs 中的 appsettings.json

这非常相似,但由于某种原因对我不起作用:ASP.NET Core 6 how to access Configuration during setup

我正在将 .NET 6 beta 应用程序移植到 .NET 6 的稳定版本。

这意味着我想移植负责导入 IConfiguration 的代码(是的,我知道它向后兼容单独的Startup.csProgram.cs文件,但我愿意使用新语法)。IConfiguration 基本上是 ASP.NET Core 中的文件 appsettings.json。

在旧代码中,它看起来像这样:

 public class Startup
    {
        internal static IConfiguration Configuration { get; private set; }
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
Run Code Online (Sandbox Code Playgroud)

我尝试了以下方法:

using Microsoft.Extensions.Configuration;
// IConfiguration init test
var Configuration = builder.Configuration;
Run Code Online (Sandbox Code Playgroud)

似乎 Microsoft.Extensions.Configuration 甚至没有被使用!我得到的语法来自这篇博客文章:https://gavilan.blog/2021/08/19/getting-the-iconfiguration-in-the-program-class-asp-net-core-6/

这个问题很原始,但我似乎没有搞清楚。感谢任何帮助解决此问题的帮助,因为它可以在新的 .NET 6 最小 API 中工作。

我发现本指南很有用,但它显然没有解决手头的问题: …

c# configuration .net-core asp.net-core .net-6.0

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

如何将 appsettings.json 配置注入到 razor 页面 C# 代码块中?

我正在关注以下官方文档:https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/ ?view=aspnetcore-6.0#access-configuration-in-razor-pages

这种实现@Configuration["myKey"]非常适合不在@{}括号之间的代码,但是当我有一个代码块时,它根本不起作用。

据我所知,该文档没有提供代码示例......

我该如何解决这个问题?

代码当然位于 Razor 页面 (.cshtml) 中。

我尝试删除@并放入不带 的相同代码@,但随后它给出了上下文错误......

PS 如果重要的话,有问题的代码是 POCO。

我使用 PPS@inject IConfiguration Configuration在 Razor 页面顶部导入配置。

我的有问题的代码:

var website = new WebSite()
        {
    private string altName = Configuration["FrameworkData:PageTitle"] +" - " +Configuration["FrameworkData:Slogan"];
    AlternateName = altName,
....
Run Code Online (Sandbox Code Playgroud)

我已经尝试在配置规范之前指定 IConfiguration 类型,但没有任何效果。

更新

我的起始代码包含有问题的部分:

@using Microsoft.AspNetCore.Http;
@using Schema.NET;
@model projectname2.Areas.MyFeature.Pages.Shared._LayoutModel
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
@{  
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" …
Run Code Online (Sandbox Code Playgroud)

c# razor asp.net-core

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

未捕获的类型错误:在多轮播中单击或自动滚动后无法读取 null 的属性(读取“classList”)

因此,我一直在关注此处的官方教程,并且此处还需要一个幻灯片指示器,因此我只是复制并修改了此处示例中的代码

我的标记如下所示:

<div class="container my-5">

  <!-- Section: Introduction -->
  <section class="">

    <p>Free example of carousel with multiple items built with the newest Bootstrap 5. Learn how to create a responsive carousel with many items inside.</p>

    <p>
      Detailed documentation and more examples you can find in our
      <a href="https://mdbootstrap.com/docs/standard/components/carousel/" target="_blank"><strong>Carousel Docs</strong></a>.
    </p>
    <p>See also <a target="_blank" href="https://mdbootstrap.com/docs/standard/plugins/multi-item-carousel/"><strong>Advanced mutli item carousel plugin</strong></a>.</p>


    <hr class="mt-5">

    <p>Built with <a target="_blank" href="https://mdbootstrap.com/docs/standard/">Material Design for Bootstrap</a> - free and powerful Bootstrap UI …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery mdbootstrap

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

失败:无法读取登录测试的未定义属性“setValue”

我写了以下测试:

import { DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { AuthenticationService } from '../services/authentication.service';
import { By } from '@angular/platform-browser';
import { LoginComponent } from './login.component';
import { ReactiveFormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { RouterTestingModule } from '@angular/router/testing';
import { GlobalDataService } from '../services/global-data.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { DatePipe } from '@angular/common';
import { MatDialogModule } from …
Run Code Online (Sandbox Code Playgroud)

jasmine typescript karma-runner karma-jasmine angular

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

没有重载匹配这个调用。最后一次重载给出了以下错误。类型 '"text"' 不能分配给类型 '"json"'

我正在尝试使用 Angular 从我的 API 获取 HTML 页面,并在标头中使用 JWT 令牌。但是,如果我不指定文本类型,编译器会发出无法解析的错误(然后它会尝试将 HTML 解析为 JSON),因此我需要指定我的响应类型。

这是我的 component.ts:

  httpOptions = {
    headers: new HttpHeaders({
      'Content-Type':  'application/json',
      'Authorization': 'Bearer TOKENHERE'
    })
  };
  constructor(private http: HttpClient) { }

  ngOnInit() {


  }
  fetchDashboard() {
    this.http.get('http://localhost:3000/avior/dashboard', {responseType: 'text', this.httpOptions,}).subscribe(j => console.log(j));
}
}
Run Code Online (Sandbox Code Playgroud)

我尝试将内容类型删除或更改为 text/html ,但没有任何效果。


我的 API 响应:

<html><head><title>Dashboard</title></head><body><h1>Dashboard works!</h1></body></html>

javascript xmlhttprequest jwt angular angular-httpclient

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

在“@angular/cdk/a11y”中找不到导出“isFakeTouchstartFromScreenReader”

我的 Angular 11 项目中突然出现以下错误:

Error: ./node_modules/@angular/material/fesm2015/core.js 1091:45-77
"export 'isFakeTouchstartFromScreenReader' was not found in '@angular/cdk/a11y'

Error: ./node_modules/@angular/material/fesm2015/menu.js 786:17-49
"export 'isFakeTouchstartFromScreenReader' was not found in '@angular/cdk/a11y'
Run Code Online (Sandbox Code Playgroud)

我试过的:

ng add @angular/material
npm i @angular/material
npm i
Run Code Online (Sandbox Code Playgroud)

javascript dependency-management typescript angular angular-cdk

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

Visual Studio 将 JavaScript 解释为 C#,这会导致错误

在我的 ASP.NET Core 项目中的代码中,我发现了导致问题的原因:有问题的代码

作为文本:

<script>
/**
     * Get a setting value.
     * @param {string} name
     * @param defaultValue
     * @returns {*}
     */
    getSetting(name, defaultValue) {
        return name in this.settings ? this.settings[name] : defaultValue;
    }
</script>
Run Code Online (Sandbox Code Playgroud)

我为每个文档代码收到的错误(红线)是https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0103 ,它被明确标识为 C#代码,即使我在 .cshtml 文件<script>标记中编写此代码...

我该如何解决?它阻止我编译和执行......

如果重要的话,我正在使用 Visual Studio 2022 Preview 4.1

javascript c# visual-studio asp.net-core visual-studio-2022

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