标签: angular7

错误:数据路径“ .builders ['app-shell']”应具有必需的属性“ class”

运行我的应用程序时出现此错误。这是我的申请的详细信息。

我已经尝试过清理缓存。

angular6 angular7

95
推荐指数
9
解决办法
6万
查看次数

带有Lazy-Loaded路由的Angular CLI HMR会重新加载整个内容

(即使使用Angular 7也确认了问题).让我们解决这个问题!

我正在使用HMR设置:https://github.com/angular/angular-cli/wiki/stories-configure-hmr from a ng newbuild build.

如果我更改任何组件并使其延迟加载,角度HMR将热重新加载所有内容,使页面同步更慢.

我知道这是因为它默认设置为console.log每个正在重新加载的模块,当我使用惰性路由时,它会记录所有内容.但是当我将该组件更改为非延迟加载时,它只记录一些小组件.

因此,当我使用HMR和懒惰路由时,我的应用程序需要几秒钟才能刷新.这很烦人.

有没有办法解决?

(懒惰的加载路线是通过这样的方式完成的)

// Main homepage
{
  path: '',
  loadChildren: './public/home/home.module#HomeModule'
},
// ...
Run Code Online (Sandbox Code Playgroud)

(只是一个例子,表明我正在以正确的方式加载)

这里有一些日志记录显示我懒惰加载时会发生什么 home.component.ts

// Everything here is normal, great!
[HMR]  - ../../../../../src/app/public/home/home.component.html
log.js:23 [HMR]  - ../../../../../src/app/public/home/home.component.ts
log.js:23 [HMR]  - ../../../../../src/app/public/home/home.module.ts
log.js:23 [HMR]  - ../../../../../src/app/public/home/home.routing.ts
// Everything below here is NOT normal, bad!  All this is extra.  These are my modules, yes, but all this needs to be loaded again?
log.js:23 …
Run Code Online (Sandbox Code Playgroud)

webpack-hmr angular-cli hot-module-replacement angular angular7

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

Angular 2/4/6/7 - 使用路由器进行单元测试

在Angular 2.0.0中,我正在测试使用Router的组件.但是我得到'提供的参数与呼叫目标的任何签名都不匹配'.错误.在spec.ts中的Visual Studio代码中,新的Router()以红色突出显示

如果有人能让我知道正确的语法是什么,我真的很感激?提前致谢.我的代码如下:

spec.ts

import { TestBed, async } from '@angular/core/testing';
import { NavToolComponent } from './nav-tool.component';
import { ComponentComm } from '../../shared/component-comm.service';
import { Router } from '@angular/router';

describe('Component: NavTool', () => {
  it('should create an instance', () => {
    let component = new NavToolComponent( new ComponentComm(), new Router());
    expect(component).toBeTruthy();
  });
});
Run Code Online (Sandbox Code Playgroud)

组件构造函数

constructor(private componentComm: ComponentComm, private router: Router) {}
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-jasmine angular angular6 angular7

56
推荐指数
4
解决办法
5万
查看次数

如何删除空间底部垫形式字段

在此处输入图片说明

我将 angular 7 与角材料一起使用,并且我想移除空间底部,如您所见。我尝试了很多方法但没有成功。

angular-material angular7

39
推荐指数
6
解决办法
4万
查看次数

Angular服务工作者在SAFE_MODE中

我有一个Angular PWA.它的服务工作者一直在完美地工作,直到我从Angular 5.0升级到7.2

升级后,我在/ ngsw/state中看到以下错误

驱动程序状态:SAFE_MODE(由于错误而导致初始化失败:违反Invariant(初始化):最新散列null没有已知的清单初始化/ <@https:// {{domain}} .com/ngsw-worker.js:2227:27已完成@https:// {{domain}} .com/ngsw-worker.js:1772:52)最新清单哈希:无最后更新检查:从不

应用背景

  • Angular版本是7.2.0
  • 服务工作者版本是7.2.0
  • 我使用SwUpdate服务手动检查更新.

用于检查更新的代码 /ngsw/state

到目前为止我的研究和故障排除步骤

在Chrome中

  • 服务工作者注册时没有任何错误
  • 我查看了网络选项卡,发现服务工作者永远不会下载'ngsw.json'.当应用程序在Angular 5.0中时,我看到'ngsw.json'被下载了

Screenshot1

  • 我看到这里报道了同样的问题.我在这里看不到任何适当的解决方案.
  • 我试过选择'重新加载更新'来暂时解决问题.我取消选择后再次显示相同的错误.

Screenshot2

在Microsoft边缘

  • 令人惊讶的是,升级后一切正常.

我的想法和期望

  • 由于应用程序在MS边缘工作正常,我怀疑服务工作者配置或我轮询更新的方式有什么问题
  • 我的期望是在/ ngsw/state中看到Drive状态为Normal

angular angular-service-worker angular7

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

Angular 6 - 提供在非根模块中导致循环依赖

我正在尝试通过新的"providedIn"属性提供解析服务.

这是我在受保护模块中使用的翻译解析器:

import { Injectable } from '@angular/core';

import { Observable , pipe } from 'rxjs';
import {map} from "rxjs/operators";

//This is causing: "WARNING in Circular dependency detected:"
import {ProtectedModule} from "../../../protected/protected.module";

import { HttpHandlerService } from '../../http/http-handler.service';

@Injectable({
  providedIn: ProtectedModule //Over here (I need the import for this line)
})
export class TranslationsResolverService {
  constructor(private _httpHandlerService : HttpHandlerService) { }
    resolve(): any {
      //Do Something...
    }
}
Run Code Online (Sandbox Code Playgroud)

我在受保护的路由模块中声明了翻译解析器服务:

import { NgModule }           from '@angular/core';
import {RouterModule, Routes} from '@angular/router'; …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular6 angular7

28
推荐指数
3
解决办法
8926
查看次数

错误TS2554:需要2个参数,但@ViewChild却有1个

我正在使用ViewChild,如下所示:

@ViewChild("InternalMedia") localStream;
@ViewChild("emoji") mEmoji;
Run Code Online (Sandbox Code Playgroud)

一直工作到angular-7.x

我将其升级到angular-8.x后,就开始出现以下错误

.../call_emoji/component.ts(41,4): error TS2554: Expected 2 arguments, but got 1.
Run Code Online (Sandbox Code Playgroud)

我检查了https://angular.io/api/core/ViewChild,并将其更改为

@ViewChild("InternalMedia",{static:false}) remoteStream;
Run Code Online (Sandbox Code Playgroud)

有用。我没有得到什么静态效果,像以前一样工作应该有什么价值?

typescript viewchild angular angular7 angular8

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

Angular 7.0.1中的Web worker设置

我正在尝试在我现有的Angular 7.0.1项目(中等规模项目)中进行Web工作者设置.我在完成以下链接后进行了设置:

以下是我对每个文件的更改:

./src/main.ts

import 'zone.js';
import { enableProdMode } from '@angular/core';
import { bootstrapWorkerUi } from '@angular/platform-webworker';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

console.log("main.ts file loaded!");
bootstrapWorkerUi('webworker.js');
Run Code Online (Sandbox Code Playgroud)

./src/workerLoader.ts

import 'polyfills.ts';
import '@angular/core';
import '@angular/common';

console.log("workerLoader.ts file loaded!");

import { platformWorkerAppDynamic } from '@angular/platform-webworker-dynamic';
import { AppModule } from './app/app.module';

platformWorkerAppDynamic().bootstrapModule(AppModule);
Run Code Online (Sandbox Code Playgroud)

./angular.json

"projects": {
  "[project name]": {
    "architect": {
      "build": { …
Run Code Online (Sandbox Code Playgroud)

web-worker typescript webpack angular angular7

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

WARNING in ./node_modules/ng2-charts/fesm5/ng2-charts.js 230:54-72 "export '??defineInjectable' was not found in '@angular/core'

I am using ng2-charts in Angular 7 app and having warning

WARNING in ./node_modules/ng2-charts/fesm5/ng2-charts.js 230:54-72 "export '??defineInjectable' was not found in '@angular/core'

error in VS Code

在此处输入图片说明

error in browser

在此处输入图片说明

What could be the reason and how to resolve it?

ng2-charts angular angular7

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

如何在 Angular 8 中重新加载或刷新子组件

我有两个组件,一个父级和另一个子级。

HTML 部分

<div>
  <div class="row col-md-12">
    <div class="col-md-4">
       <!-- Some HTML Code of Parent component over here -->
    </div>
    <div class="col-md-8">
      <child-component></child-component>
    </div>
 </div>
 <button class="button" (click)="reloadOnlyChild($event)">Reload Child</button>
</div>
Run Code Online (Sandbox Code Playgroud)

现在,单击此按钮后,我希望唯一的孩子重新加载或刷新。

TS部分

reloadOnlyChild(event){
  // I want to reload the child from here.
}
Run Code Online (Sandbox Code Playgroud)

我在互联网上搜索,我得到的是 Vue 或 React,但不是 Angular。

angular angular5 angular6 angular7 angular8

19
推荐指数
5
解决办法
4万
查看次数