我正在按照 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) 这似乎是一个类似的问题,但没有一个答案适合我的代码...:阅读 Main Program.cs 中的 appsettings.json
这非常相似,但由于某种原因对我不起作用:ASP.NET Core 6 how to access Configuration during setup
我正在将 .NET 6 beta 应用程序移植到 .NET 6 的稳定版本。
这意味着我想移植负责导入 IConfiguration 的代码(是的,我知道它向后兼容单独的Startup.cs
和Program.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 中工作。
我发现本指南很有用,但它显然没有解决手头的问题: …
这种实现@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) 因此,我一直在关注此处的官方教程,并且此处还需要一个幻灯片指示器,因此我只是复制并修改了此处示例中的代码。
我的标记如下所示:
<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) 我写了以下测试:
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) 我正在尝试使用 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>
我的 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
在我的 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
angular ×4
javascript ×4
asp.net-core ×3
c# ×3
typescript ×3
.net-6.0 ×1
.net-core ×1
angular-cdk ×1
angular-ivy ×1
css ×1
html ×1
jasmine ×1
jquery ×1
jwt ×1
karma-runner ×1
mdbootstrap ×1
razor ×1