标签: angular-cli

任何适用的指令或表单元素均未提供属性 formGroup (特别是 Angular CLI 13.0.4)

ReactiveFormsModule这不是导入或导入的问题FormsModule

我已经在 app.module.ts 和遇到此问题的模块中导入了这些内容:

  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule,
    ReactiveFormsModule,
    ...
Run Code Online (Sandbox Code Playgroud)

所以当我将属性[formGroup]和formControlName属性添加到.html file

<form  [formGroup]="loginForm" (ngSubmit)="doLogin()" class="m-t" role="form" action="index.html">
  <div class="form-group">
    <input type="email" class="form-control" formControlName="username" placeholder="Username" required="">
  </div>
  <div class="form-group">
    <input type="password" class="form-control" formControlName="password" placeholder="Password" required="">
  </div>
</form>
Run Code Online (Sandbox Code Playgroud)

当我将 CLI 从 升级12.1.0到13.0.4

如果我降级到以前的版本,错误就会消失。

我已删除节点模块文件夹并重新运行npm install

由于此版本的 CLI 已于7 天前发布,因此我找不到此错误的任何解决方案。我还访问了Github 上的Angular cli 问题页面,但那里尚未提出任何问题。

如果有任何解决此问题的建议,我将不胜感激。降级不是一个选择。

npm typescript angular-directive angular-cli angular

6
推荐指数
0
解决办法
2403
查看次数

未描述的 Angular NG0203 控制台消息

当我将 MatProgressSpinnerModule 加载到 app.module.ts 中时,我收到带有“stacktrace”的空 NG0203 错误:

    tQ https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    re https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    fac https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    hydrate https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    get https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    _resolveInjectorDefTypes https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    _resolveInjectorDefTypes https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    PM https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    create https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    wA https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    invoke https://localhost:44378/client/polyfills.js:1
    onInvoke https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    invoke https://localhost:44378/client/polyfills.js:1
    run https://localhost:44378/client/polyfills.js:1
    run https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    bootstrapModuleFactory https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    wA https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    invoke https://localhost:44378/client/polyfills.js:1
    run https://localhost:44378/client/polyfills.js:1
    F https://localhost:44378/client/polyfills.js:1
    invokeTask https://localhost:44378/client/polyfills.js:1
    runTask https://localhost:44378/client/polyfills.js:1
    L https://localhost:44378/client/polyfills.js:1
    promise callback*d https://localhost:44378/client/polyfills.js:1
    scheduleTask https://localhost:44378/client/polyfills.js:1
    scheduleTask https://localhost:44378/client/polyfills.js:1
    scheduleMicroTask https://localhost:44378/client/polyfills.js:1
    F https://localhost:44378/client/polyfills.js:1
    then https://localhost:44378/client/polyfills.js:1
    bootstrapModule https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    636 https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    n https://localhost:44378/client/runtime.js:1
    <anonymous> https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    a https://localhost:44378/client/runtime.js:1
    <anonymous> https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1

Run Code Online (Sandbox Code Playgroud)

应用程序模块.ts:

import …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular

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

Firefox 中间歇性出现 Webpack ChunkLoadError 的根源是什么?

我在一个网站上工作,该网站有一个 Angular 前端,可以通过 webpack(通过 angular-cli)延迟加载 js 块。

我们的一些 Firefox 用户(仅限 Firefox)间歇性地遇到一个问题,其中一个 js 块无法加载,从而导致 ChunkLoadError。当他们清除 Firefox 缓存并重试时,Firefox 将(正确)加载之前无法加载的 js 块。我从多个受影响的用户处获取了 HAR 文件,并亲眼目睹了该模式。例如,在我分享的屏幕截图中,单个文件显示传输了 -1 字节,状态代码为 0。看起来 Firefox 甚至没有尝试发送请求,但这可能是缓存的产物。 在此输入图像描述

这是来自另一个用户的类似但略有不同的 HAR。该错误表现相同。请注意,在这种情况下,有响应,但仍传输 -1 字节。 在此输入图像描述

我在 StackOverflow(和其他地方)上看到过其他类似的问题,这些问题讨论了由于部署新代码而导致的块消失,但这不是这里的问题——清除缓存之前和之后的文件名是相同的,并且这些部署后不会出现问题。

我怀疑有扩展程序或附加组件(可能是某种 js 或广告拦截器),但一些受影响的用户发誓即使所有扩展程序都被禁用,他们也会看到问题。现在,我最好的猜测是 Firefox 本身的缓存系统存在某种问题,但实际上,这只是一个随机猜测。

我知道这不足以调试此问题,但我希望这可能会给某人敲响警钟,他们可以为我指明正确的方向。当然,我自己复制这个的运气为零。

以下是用户报告问题的两个讨论(在我们的网站上),包括一些技术细节:

https://boardgamegeek.com/thread/2800974/cant-open-forum-threads-firefox https://boardgamegeek.com/thread/2788693/special-videos-page-immediately-redirects-me-empt

一些相关的技术细节:我们使用的是 Angular 13.2.1,Angular-CLI 使用的是 webpack 5.67.0。块本身存储在 S3 上并通过 Amazon CloudFront 提供服务。Firefox 版本因用户而异,但至少在 96 版本的 Firefox 中都会出现此问题。

firefox webpack angular-cli angular

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

带有针对 ES2022 的 Angular (15) 的 ClassDecorator

目前是 2023 年 3 月,我正在寻找一种方法让我的类装饰器以正确的方式工作,而不需要来自 cli 的警告。

这是我的简单代码:

function MyDecorator(myConstructor: new (...args: any[]) => any): new (...args: any[]) => any {
  alert('MyDecorator EVALUATE'); // -------------> Alert A
  return class extends myConstructor {
    constructor(...args) {
      super(...args);
      alert('MyDecorator CONSTRUCTOR'); // ------------> Alert B
    }
  };
}

@MyDecorator
@Component({
  // ...
})
export class AppComponent() {
  // ...
} 
Run Code Online (Sandbox Code Playgroud)

Angular 15 之前:

我的目标是 ES2021 或更低版本,这非常有效。我收到警报 A 和 B,但 cli 没有发出任何警告。

使用 Angular 15:

我的目标仍然是 ES2021,它仍然有效。我收到警报 A 和 B

但cli 警告我它覆盖了一些设置。

TypeScript compiler …
Run Code Online (Sandbox Code Playgroud)

decorator tsconfig angular-cli angular es2022

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

如何使用material2工具栏,按钮和angular-cli路由器

我有以下文件:

html的

<nav>
  <md-toolbar color = "primary">
    <a [routerLink] = "['new-patient']">New Patient</a>

    <button md-icon-button
            color = "accent">
      <md-icon class = "material-icons md-24">person_add</md-icon>
    </button>
  </md-toolbar>
</nav>
Run Code Online (Sandbox Code Playgroud)

.TS

import { Component, OnInit } from '@angular/core';
import { ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router';
import { MdToolbar } from '@angular2-material/toolbar';
import { MdIcon, MdIconRegistry } from '@angular2-material/icon';
import { MdButton } from '@angular2-material/button';

@Component({
  moduleId: module.id,
  selector: 'epimss-toolbar',
  templateUrl: 'toolbar.component.html',
  styleUrls: ['toolbar.component.css'],
  providers: [MdIconRegistry],
 directives: [MdButton, MdIcon, MdToolbar, ROUTER_DIRECTIVES],
})
export class ToolbarComponent implements …
Run Code Online (Sandbox Code Playgroud)

typescript1.8 angular-cli angular-material2 angular

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

Angular CLI不会创建新项目

我正在尝试通过angular cli创建一个项目(名为ngadmin),但它会在此命令上抛出错误:ng new ngadmin.错误是:

fs:不支持重新评估本机模块源.如果您使用的是graceful-fs模块,请将其更新为更新版本.

您不能在angular-cli项目中使用new命令.

我不确定问题是什么,因为这个cli几天前对我来说很好.

angular-cli angular

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

Angular 2 AoT ngc不生成任何文件

当我在angular-cli创建的Angular 2 RC5 vanilla项目上运行离线编译器ngc时,它什么也没做.

这就是我做的

建立:

ng new my-project
cd my-project
npm install @angular/compiler-cli typescript@next @angular/platform-server @angular/compiler
Run Code Online (Sandbox Code Playgroud)

运行编译器

./node_modules/.bin/ngc -p ./src
Run Code Online (Sandbox Code Playgroud)

命令输出什么,我没有看到它生成min.ngfactory.ts

我错过了什么?

compilation tsc angular-cli angular

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

如何在angular cli中使用模块名称别名?

使用独立webpack,您可以使用别名进行模块解析.你的webpack.config文件中的这样的东西,config.resolve块:

config.resolve = {
    extensions: ['', '.ts', '.js', '.json', '.css', '.scss', '.html'],
    alias: {
      'app': 'src/app',
      'common': 'src/common',
       'a_module_name': 'file_path_to_module_name'
    }
  };
Run Code Online (Sandbox Code Playgroud)

你如何在angular cli中使用webpack,如别名解析?

webpack angular-cli

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

Angular 2 TestModuleMetadata没有EntryComponents属性

我正在使用Angular CLI 1.0.0-beta.32.2并正在为Angular 2服务编写单元测试,该服务动态创建一个Component并将其插入另一个Component.

在我的单元测试中,我尝试创建一个模拟组件来测试我的服务,但输出会ng test抛出一个错误,说明我的模拟组件是在entryComponents属性中指定的.当我尝试将Component添加到entryComponentsTestModuleMetadata对象的属性中时,如下所示:TestBed.createTestingModule({...entryComponents: [ TestDialogComponent ]...})我看到以下错误说明该entryComponents属性不存在.

Chrome 56.0.2924 (Windows 10 0.0.0) DialogService should create a child component when opening FAILED Error: No component factory found for TestDialogComponent. Did you add it to @NgModule.entryComponents?

查看TestModuleMetadata定义显示entryComponents属性不存在.那么如何在Angular 2和Jasmine的单元测试中动态创建一个Component呢?

unit-testing typescript angular-cli angular

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

angular2:如何通过条件手动将css文件添加到index.html?

下面的代码是为样式定义的.

<!-- for mobile -->
<link rel="stylesheet" href="/dist/css/mobile.css">

<!-- for desktop -->    
<link rel="stylesheet" href="/dist/css/desktop.css">
Run Code Online (Sandbox Code Playgroud)

我想按条件将上面的文件添加到'src/index.html'中的<head>.

如何为每个设备应用css文件?

如您所知,我不能在'index.html'中使用'条件'代码.

请注意,我不会使用以下方法.

// in angular-cli.json
"apps": [
    {
        "root": "src",
        "index": "index.html",
        "styles": [
            "/dist/css/mobile.css",
            "/dist/css/desktop.css"
        ]
    }
]


// in component.ts
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrl: '/dist/css/mobile.css'
})
Run Code Online (Sandbox Code Playgroud)

我期待着你的建议.

谢谢.

css external angular-cli angular

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