这个问题花了我一整天的时间,我不明白发生了什么
我可以看到我的 Service Worker 已注册,但是“有时”当我在开发人员工具中单击离线时,我的域的 ServiceWorker 就会消失!
但这是主要问题,当我重新加载应用程序时,我看到以下行为。
您可以看到 ngsw.json 加载了两次,main.js 加载了 3 次!main.d3ae2084xxxx && main.bbe5073dxxxx && 然后再次 main.d3ae2084xxxx !
如果我检查两个 ngsw.json 请求的响应,您可以看到两者都显示 main.d3ae2084xxxx 作为 main.js 的正确版本,但它仍然加载 main.bbe5073dxxxx...
第一个 ngsw.json 请求
第二个 ngsw.json 请求
更令人沮丧的是,实际加载的版本是以前的main.bbe5073dxxxx...!!!!
如果有人有任何想法如何发生这种情况,请告诉我。
更新...所以发现了这个优秀的小端点
https://you-app-url/ngsw/state
Run Code Online (Sandbox Code Playgroud)
这将为您提供有关 Service Worker 的大量调试信息。
就我而言,这个
驱动程序状态:EXISTING_CLIENTS_ONLY(由于初始化失败而降级:哈希不匹配(cacheBustedFetchFromNetwork): https://dev-xxxx.net/main.eb8468bb3ed28f02d7c2.js:预期b5601102b721e0cf777691d327dc965d40d1c96e,得到83c18fdb4a594 2c964a31c119a57e0b8e16fe46e(缓存清除后)
因此,在我的情况下,这似乎是某种 CDN 问题,当我确定时将更新答案。
我正在学习 Angular 6 的 MEAN 堆栈应用程序。在这里,我想在添加新的客户端/汽车/司机/预订或更新新的客户端/汽车/司机/预订后刷新组件。但是添加新值后,显示所有值的组件不会更新或刷新(当时无法看到当前值),但是当我在组件之间路由然后返回到它更新并显示的同一组件时所有的值。
我希望当从对话框表单添加或更新值时,它会在那时显示。
这是add client component
export class AddClientComponent implements OnInit {
clientForm: FormGroup;
constructor(private fb: FormBuilder,
private clientService: ClientService,
private toastr: ToastrService,
private router: Router,
public dialogRef: MatDialogRef < AddClientComponent > ) {
this.clientForm = this.fb.group({
'clientname': new FormControl(""),
'clientphoneno': new FormControl(""),
'clientemail': new FormControl(""),
'clientaddress': new FormControl("")
});
}
ngOnInit() {
this.router.navigate(['/admin/clients']);
}
saveClient(formdata: any) {
let theForm = this.clientForm.value;
this.clientService.addClient(theForm).subscribe(data => {
if (data.success === false) {
this.toastr.error(data.message);
} else {
this.toastr.success(data.message); …Run Code Online (Sandbox Code Playgroud)我有一个input HTML File归档
<input type="file" class="custom-file-input" id="question-file-upload" formControlName="image" (change)="handleFileSelect($event)">
Run Code Online (Sandbox Code Playgroud)
我想对handleFileSelect功能进行单元测试。但我不知道如何触发onChange输入的方法。以下是spec我写的,但出现错误imageInputNE.onchange is not a function
fit('should keep track of image counter when an image is loaded', () => {
let newPracticeQuestionComponent = component;
expect(newPracticeQuestionComponent.currentImageAttachmentCount).toBe(0);
let imageInputDE = fixture.debugElement.query(By.css("#question-file-upload"));
expect(imageInputDE).toBeTruthy();
spyOn(newPracticeQuestionComponent,'handleFileSelect');
let imageInputNE:HTMLElement = imageInputDE.nativeElement as HTMLElement;
imageInputNE.onchange(new Event("some event"));
expect(newPracticeQuestionComponent.handleFileSelect).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试做一个剑道聊天示例:https://www.telerik.com/kendo-angular-ui/components/conversationalui/ 我使用 Visual Studio 代码和 Angular 6,我在谷歌中搜索但找不到解决方案但是我得到这个错误:
src/app/app.component.ts(68,7) 中的错误:错误 TS2345:“MonoTypeOperatorFunction”类型的参数不可分配给“OperatorFunction”类型的参数。参数“source”和“source”的类型不兼容。类型“Observable”不可分配给类型“Observable”。类型“Message”不可分配给类型“any[]”。“消息”类型中缺少属性“长度”。
我的组件是:
import { Component } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { switchMap } from 'rxjs/operators/switchMap';
import { map } from 'rxjs/operators/map';
import { windowCount } from 'rxjs/operators/windowCount';
import { scan } from 'rxjs/operators/scan';
import { take } from 'rxjs/operators/take';
import { tap } from 'rxjs/operators/tap';
import { from } from 'rxjs/observable/from';
import { merge } from 'rxjs/observable/merge';
import { ChatModule, Message, User, Action, ExecuteActionEvent, SendMessageEvent …Run Code Online (Sandbox Code Playgroud) 我想检查一个网址是否存在。我正在尝试使用这段代码:
let request;
if ((<any>window).XMLHttpRequest) {
request = new XMLHttpRequest;
request.open('GET', 'http://www.mozilla.org', true);
} else if ((<any>window).ActiveXObject) {
request = new ActiveXObject('Microsoft.XMLHttp');
}
if (request) {
console.log('rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr', request);
request.open('GET', 'https://www.google.com');
if (request.status === 200) {
console.log('Valid Url');
} else {
console.log('Invalid Url');
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用。它总是返回无效的网址。如何检查 url 是否存在。
我有一个使用 Angular Material 的 Angular 7 项目。我还在我的输入标签中使用了时间类型(HTML5)
<input type="time">
Run Code Online (Sandbox Code Playgroud)
但我希望它是 24 小时格式(不显示 AM/PM 选项)。我一直在寻找解决方案,但没有一个适合 Angular Material 项目。
我是 Angular 的初学者,我在大学项目中使用了 Angular 6,我创建了一个侧边栏并且运行良好,但是当我尝试添加子菜单时它不起作用。
我想知道如何正确地做到这一点。
子菜单示例
侧边栏.ts
import { Component, OnInit } from '@angular/core';
declare const $: any;
declare interface RouteInfo {
path: string;
title: string;
icon: string;
class: string;
}
export const ROUTES: RouteInfo[] = [
{ path: '/dashboard', title: 'Dashboard', icon: 'home', class: '' },
{ path: '/class', title: 'Class', icon: 'description', class: '' },
{ path: '/student', title: 'Students', icon: 'apps', class: '' },
{ path: '/profile', title: 'Profile', icon: 'person', class: '' },
]; …Run Code Online (Sandbox Code Playgroud) 我有一个名为的组件,customers-list我在其中显示 API 中的所有客户:
客户列表.html
<div *ngFor="let customer of customers">
<p>{{customer.name}</p>
</div>
Run Code Online (Sandbox Code Playgroud)
客户列表.ts
import { Component Input} from '@angular/core';
import { ICustomer} from 'src/app/models/app.models';
import { CustomersService } from 'src/app/services/customers.service';
@Component({
selector: 'drt-customers-list',
templateUrl: './customers-list.component.html',
styleUrls: ['./customers-list.component.scss'],
})
export class CustomerListComponent {
public customers: ICustomer[] ;
constructor(public customersService: CustomersService,) {}
public async ngOnInit(): Promise<void> {
this.customers = await this.customersService.getCustomersList('');
}
}
Run Code Online (Sandbox Code Playgroud)
我有另一个名为 的组件add-customer,我将在其中添加新客户,如下所示:
public onaddCustomer(): void {
this.someCustomer = this.addCustomerForm.value;
this.customersService.addCustomer( this.someCustomer).subscribe(
() => { // If …Run Code Online (Sandbox Code Playgroud) 我有一个有角度的材料树,它应该在树内的树节点内有过滤器(第三级)。当我单击子项时,过滤器应该与孙子项一起出现。我看到下面的示例,其中过滤树外部并过滤整个节点:
https://stackblitz.com/edit/angular-yb37gh?file=app%2Ftree-checklist-example.html
如果我们看上面的例子,我需要在伊斯坦布尔下进行过滤,并且它应该提供过滤下面的子元素的功能。我的意思是在孙子级别上进行过滤,并且应该能够仅过滤孙子
我尝试过一个示例,其中当 I.filter 孙子时,它将重新渲染树,并且由于树本身内部的过滤器,过滤器也会重新渲染,因此我无法保留过滤器上的值。
有人遇到过在树内添加过滤器吗?请帮忙
我期待像下面这样的东西。仅搜索该级别上的所有节点。

我们有一个 Angular 6 项目,其中在 node_modules 文件夹中包含大约 660 MB 的包。自项目启动以来,在构建项目时,我们将删除整个 node_modules 文件夹,然后执行 npm install 来重新下载并安装package.json.
然而,构建时间已增加至 15 - 20 分钟。如果我们注释掉删除该文件夹的命令,则构建时间将在 3 - 4 分钟之间。始终拥有已定义软件包的全新下载会给我们带来什么好处?
angular6 ×10
angular ×6
typescript ×3
angular-pwa ×1
angular-test ×1
angular7 ×1
express ×1
filter ×1
html ×1
jenkins ×1
node-modules ×1
node.js ×1
rxjs ×1
timepicker ×1
tree ×1