我想测试下面的代码,但我不确定如何测试地图和点击(来自 RXJS)功能。我应该模仿,使用间谍吗?
我真的应该测试这些吗?我有一个习惯,即只为了实现该目标(100% 覆盖率)而获得 100% 覆盖率,但我了解到 100% 并不总是需要的或有益的。但在这种情况下,地图和点击对于该功能来说非常关键。我真的很感激任何建议,谢谢。
我正在使用 Angular 9。
红线未经测试。
升级到 Angular 9 并尝试运行我的项目后,我收到此错误:
Compiling @angular/common/http : module as esm5
Compiling angular-font-awesome : module as esm5
Compiling angular-font-awesome : module as esm5
Error: Error on worker #5: Error: Failed to find exported name of node (CommonModule = (function () {
function CommonModule() {
}
return CommonModule;
}())) in 'C:/Users/.../node_modules/angular-font-awesome/dist/angular-font-awesome.es5.js'.
at Object.findExportedNameOfNode (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\find_export.js:35:19)
at LogicalProjectStrategy.emit (C:\Users\Ghaida\...\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:228:38)
at ReferenceEmitter.emit (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:71:44)
at Object.toR3Reference (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\util.js:173:31)
at NgModuleDecoratorHandler._toR3Reference (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:415:31)
at C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:196:72
at Array.map (<anonymous>)
at NgModuleDecoratorHandler.analyze (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:196:38)
Run Code Online (Sandbox Code Playgroud)
这是运行 ng version 的结果:
Angular CLI: 9.1.0
Node: …Run Code Online (Sandbox Code Playgroud) 我需要在我的 Web 应用程序中实现国际手机号码的输入,但我几乎找不到任何支持 Angular 9 版本的。你有什么建议?谢谢
如何使用去抖时间在 API 中搜索 keyup 输入更改事件的数据。看看下面的代码。它不起作用。每次输入更改时都会向 API 发出搜索请求。我想使用一些开发时间向 API 发出搜索请求。
先感谢您
.html
<input matInput (keyup) ="Onsearchinput($event.target.value)">
Run Code Online (Sandbox Code Playgroud)
.ts
Onsearchinput(value){
debounceTime(500)
console.log(value)
this.productService.search_Products(value).subscribe(data => {
if(data){
console.log(data)
this.product_list = data
}
})
}
Run Code Online (Sandbox Code Playgroud) 我有一个有条件检查的 Angular 循环。因此,在数组上使用 .length 或使用 i from index 的通常答案不会告诉我有多少项目正在显示。
<form [formGroup]="paymentsForm">
<div formArrayName="arrVoucherLines">
<div *ngFor="let line of paymentsForm.get('arrVoucherLines')['controls']; index as i"
[formGroupName]="i">
<div *ngIf="dateCheckingConditionalFunctionPlaceholder()">
<mat-checkbox formControlName='FlagPayInvoice'></mat-checkbox>
Issued: {{line.value.DateTimeLocalInvoiceIssued |date:'MM/dd'}}
Due: {{line.value.DateTimeLocalInvoiceDue |date:'MM/dd'}}
... variety of other voucer info
</div>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
显示项目总数很容易,但我还希望能够显示显示了多少以及跳过了多少。如果我可以在循环中有一个“变量++”,那就很容易了。
期望的结果是得到一些我可以做到的:
Total invoices {{blah.length}}
Invoices Shown {{count}}
Invoices not yet due: {{blah.length-count}}
Run Code Online (Sandbox Code Playgroud)
用例是用户在表单上选择截止日期,并且只显示该日期之前到期的账单。
我从 Angular 9.17 升级到 9.19,现在 ng build 失败并出现以下错误,抱怨@types/node 和 zone.js 中的变量声明:
node_modules/@types/node/ts3.5/globals.global.d.ts:1:13 中的错误 - 错误 TS2403:后续变量声明必须具有相同的类型。变量“global”必须是“Global”类型,但这里的类型是“Global & typeof globalThis”。
1 声明var global: NodeJS.Global & typeof globalThis; ~~~~~~
node_modules/zone.js/dist/zone.js.d.ts:600:13 600 声明 var global: NodeJS.Global; ~~~~~~ 'global' 也在这里声明。
升级前运行良好,现在无法构建。这是唯一的变化。
请帮忙。
我的 package.json
{
"name": "myapp",
"private": true,
"version": "1.0.0",
"scripts": {
"ng": "ng",
"start": "echo hello && ng serve --live-reload=false",
"build": "node --max_old_space_size=4096 ng build",
"build:ssr": "ng run MIC:server:dev",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"postcss": {},
"dependencies": …Run Code Online (Sandbox Code Playgroud)我使用“ng g pipe”命令创建了一个管道。在我的代码中使用它时出现控制台错误。下面附上代码的截图。错误:错误 NG8004:未找到名称为 'filterByPrcName' 的管道。 filter-by-prc-name.pipe.ts控制台错误信息 product-list.component.html
这是我的 appModule,我正在使用 ng-boostsrap 轮播
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { NgbModule, NgbCarousel } from '@ng-bootstrap/ng-bootstrap';
@NgModule({
declarations: [
AppComponent,
HomeComponent
],
imports: [
BrowserModule,
AppRoutingModule,
NgbModule,
NgbCarousel
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
每当我添加任何 ng-bootstrap 组件时,它都会出现以下错误,在这里我添加了轮播。
ERROR in node_modules/@ng-bootstrap/ng-bootstrap/carousel/carousel.d.ts:24:22 - error NG6002: Appears in the NgModule.imports of AppModule, but …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法
将建造/声明时的全新日期转换为太平洋标准时间。(无需团队中的每个开发人员手动设置时区)
此外,当以 HTMLconsole.log等格式显示时,显示的日期应以太平洋时区显示
let test = new Date(2019, 3, 5);
console.log(test);
Run Code Online (Sandbox Code Playgroud)如何才能做到这一点?Angular 中是否有全局参数来设置它,也许在配置文件中?
*我们在代码库中有 500 行日期代码,需要进行这种全局转换。有时当人们在不同的时区工作时,应用程序会呈现不同的时区日期。需要更正以前人的代码。
当前无法将这些行转换为 Moment,在当前代码库中使用 Date。
另外,这会是一个合适的解决方案吗?tzutil /s "Pacific Standard Time",刚刚在谷歌了解到这个
有问题 jsPDF 的 Angular 9 模块(已安装的类型 + 包本身)
当做 ng serve 时,它工作 当做 ng build --prod 时,它有错误
ERROR in src/app/xxx/xxxx.componentomponent.ts:52:27 - error TS2351: This expression is not constructable.
Type 'typeof jsPDF' has no construct signatures.
52 let pdf = new jsPDF('p', 'mm', 'a4');
~~~~~
src/app/xxx/xxxx.component.ts:7:1
7 import * as jsPDF from 'jspdf';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import …Run Code Online (Sandbox Code Playgroud) angular9 ×10
angular ×9
typescript ×3
angular8 ×2
javascript ×2
angular-cli ×1
angular-pipe ×1
carousel ×1
jasmine ×1
jspdf ×1
ng-bootstrap ×1
npm ×1
rxjs ×1
testing ×1
unit-testing ×1
web-frontend ×1
zonejs ×1