我有这个代码:
this.form = fb.group({
username: ['', Validators.compose([Validators.required])],
fullName: ['', Validators.compose([Validators.required])],
password: ['', Validators.compose([Validators.required])],
confirmPassword: ['', Validators.required],
}, {validator: matchingPasswords('password', 'confirmPassword')});
Run Code Online (Sandbox Code Playgroud)
matchingPasswords:
export function matchingPasswords(passwordKey: string, passwordConfirmationKey: string) {
return (group: FormGroup) => {
let password = group.controls[passwordKey];
let passwordConfirmation = group.controls[passwordConfirmationKey];
if (password.value !== passwordConfirmation.value) {
return passwordConfirmation.setErrors({mismatchedPasswords: true})
}
}
Run Code Online (Sandbox Code Playgroud)
}
HTML:
<div class="form-group">
<input [formControl]="confirmPassword" class="form-control checking-field" type="password">
<span class="help-block text-danger" *ngIf="form.get('password').touched && form.get('password').hasError('required')">
</div>
<div class="form-group">
<input class="custom-control-input checkbox-main" type="checkbox" [(ngModel)]="policyButtonValue" [ngModelOptions]="{standalone: true}" ngDefaultControl>
<span class="custom-control-indicator"></span>
</div> …Run Code Online (Sandbox Code Playgroud) 当我将鼠标悬停在不同组件中的元素之一上时,我试图动态更改 google 标记的颜色。我仍在学习 Angular,我尝试使用 Observables 但没有任何成功。
我有main.view 存储所有卡片的组件(我称之为事件)。这是main-view.component.ts代码的一部分:
constructor( private eventService: EventsDataService) {
}
ngOnInit() {
this.getEvents();
}
Run Code Online (Sandbox Code Playgroud)
我正在注入从服务器获取卡片数据的服务,并使用getEvents方法使用 Observable 将其转换为 JSON 数据。然后我在html模板中使用 2 个 *ngFor 指令来迭代这些数据并填充卡片和标记。这是代码:
main-view.component.html
<app-event-card *ngFor="let event of events; let i = index"></app-event-card>
</section>
<aside class="mapContainer" [class.fixed]="fixed">
<agm-map [class.fixed]="fixed" [latitude]= "latitude" [longitude]="longitude" >
<agm-marker *ngFor="let event of events; let i = index"
[latitude]= "event.location.coordinates[0]"
[longitude]="event.location.coordinates[1]"
label="{{event.price +'AUD'}}">
</agm-marker>
</agm-map>
</aside>
Run Code Online (Sandbox Code Playgroud)
现在,当我将鼠标悬停在与标记相对应的一张卡片上时,我想更改标记的颜色或任何属性,但我不知道如何连接这两个组件的数据。
我将不胜感激有关此问题的任何帮助或提示。
谢谢
正如此问题所述,如果您尝试使用指令访问 ngControl.control:
export class DisabledDirective {
@Input()
set opDisabled(condition: boolean) {
const action = condition ? 'disable' : 'enable';
this.ngControl.control[action]();
}
constructor(private ngControl: NgControl) {}
}
Run Code Online (Sandbox Code Playgroud)
第一次渲染时会出现错误:
core.js:5828 ERROR TypeError: Cannot read property 'disable' of undefined
Run Code Online (Sandbox Code Playgroud) 我有一个旧的 Angular 应用程序,我已将其从 Angular 9 升级到 Angular 11。(从 Angular 2 开始,多年来它进行了许多稳定的升级)
\n我的问题是,它ngcc没有运行ng build:
$ ng build\n \'node-sass\' usage is deprecated and will be removed in a future major version. To opt-out of the deprecated behaviour and start using \'sass\' uninstall \'node-sass\'.\n\xe2\x9c\x94 Browser application bundle generation complete.\n\nError: node_modules/ngx-device-detector/index.d.ts:3:23 - error TS2314: Generic type \'ModuleWithProviders<T>\' requires 1 type argument(s).\n\n3 static forRoot(): ModuleWithProviders;\n ~~~~~~~~~~~~~~~~~~~\nnode_modules/@ngx-translate/core/public_api.d.ts:22:53 - error TS2314: Generic type \'ModuleWithProviders<T>\' requires 1 type argument(s).\n\n22 static forRoot(config?: TranslateModuleConfig): …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular 应用程序,需要发送 N 个 XHTTP 请求,其中 1 <= N <= 10000。
应用程序需要尽可能快地处理它,因此最好同时有多个活动的 XHTTP 请求,并具有同时多个请求的滑动窗口。由于服务器端 API 限制,无法使用 WebSocket 或其他类似流式处理的解决方案。
我的第一个想法是使用RxJS forkJoin之类的东西,但我很难限制并发请求数。据我所知,API 对最大请求数有限制,例如Chrome 只允许 8 个并发请求。
我发现的大多数解决方案/教程要么 a.) 不限制最大并发连接数,要么 b.) 不动态更新(超时解决方案对此任务效率不高)。
例如:
const test = () =>
request(`https://swapi.co/api/people/1/`)
.pipe(
delay(1000),
switchMap(response => from(response.films)),
concatMap((url: string) => request(url).pipe(delay(1000))),
scan((acc, res) => [...acc, res.title], []),
tap(console.log)
)
.subscribe()
Run Code Online (Sandbox Code Playgroud)
这对我来说不好,因为限制是通过延迟实现的,但我想实现类似基于线程的解决方案:最多有 Y 个并发连接,如果一个连接完成,则立即启动一个新请求。
const test = () =>
request(`https://swapi.co/api/people/1/`)
.pipe{
switchMap(response => from(response.films)),
specialOperatorIAmLookingFor((url: string) => request(url), 8), // …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的本地分支合并到服务器VSTS上的Target分支,但始终失败,并显示以下错误消息:-
EXEC:EXEC(0,0):错误:找不到:python2
我的本地发布效果很好,但仅在将任何源合并到VSTS上的目标分支时才出现问题。
所以我在这个 stackblitz 示例中有一个代码。
基本上有一个简单的表单,带有一个输入和一个按钮。按下按钮会将输入的当前值复制到标签:
点击后:
html:
<input id="inputID" [(ngModel)]="inputValue" />
<button id="buttonID" (click)="set()">send</button>
<hr/>
<label> new Value: {{labelValue}} </label>
<hr/>
Run Code Online (Sandbox Code Playgroud)
JS:
labelValue = "";
inputValue = "defaultValue";
set(){
this.labelValue = JSON.parse(JSON.stringify(this.inputValue));
}
Run Code Online (Sandbox Code Playgroud)
我必须仅使用本机 JS 代码来模拟用户交互。 所以我尝试以下操作(例如在浏览器控制台中):
- document.getElementById('inputID').value = "aNewValue";
- document.getElementById('buttonID').click();
Run Code Online (Sandbox Code Playgroud)
问题是这样的:
我在标签中获得了默认值,而不是当前值。我怎样才能获得正确的价值?我怀疑它与反射属性有关,但无法弄清楚这里可能是什么问题。
更新:我尝试了以下方法,但也没有运气。
element = document.getElementById('inputID')
element.value = "aNewValue";
var ev = new Event('change', {
view: window,
bubbles: true,
cancelable: true,
});
element.dispatchEvent(ev);
document.getElementById('buttonID').click();
Run Code Online (Sandbox Code Playgroud) 我有以下材料菜单:
<a mat-button [matMenuTriggerFor]="menu" disabled="true">Menu</a>
<mat-menu #menu="matMenu">
<button mat-menu-item>Item 1</button>
<button mat-menu-item>Item 2</button>
</mat-menu>
Run Code Online (Sandbox Code Playgroud)
请注意,我有一个<a>标签而不是一个<button>.
我想禁用mat菜单触发器.如果我使用按钮标签,它可以工作,如果我将它用作ancor标签,它仍会打开菜单:
任何想法如何通过anchor链接标签来防止这种情况?
Stackblitz的例子在这里.
运行flutter build web出现如下错误:
flutter build web\nChanging current working directory to: /home/forest/projects/icell/i_cell_parking_manager\n\nBuilding without sound null safety\nFor more information see https://dart.dev/null-safety/unsound-null-safety\n\nTarget dart2js failed: Exception: ../../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-1.0.1/lib/src/interop/utils/utils.dart:15:41:\nError: The argument type 'Object? Function(Object)' can't be assigned to the parameter type 'Object? Function(Object?)?' because 'Object?' is nullable and 'Object' isn't.\n - 'Object' is from 'dart:core'.\n return core_interop.dartify(jsObject, (Object object) {\n ^\n../../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-1.0.1/lib/src/interop/utils/utils.dart:39:41:\nError: The argument type 'dynamic Function(Object)' can't be assigned to the parameter type 'Object? Function(Object?)?' because 'Object?' is nullable and 'Object' isn't.\n - …Run Code Online (Sandbox Code Playgroud) 如果用户未在 .txt 文件中选择值(或清除选择),我需要显示特殊字符串“未选择任何值” mat-select。
我想使用该属性,如文档placeholder中所示。
<h4>Basic mat-select</h4>
<mat-form-field>
<mat-label>Favorite food</mat-label>
<mat-select placeholder="No value selected"> <!-- this is not showing-->
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
但是,如果我应用该属性,占位符就会被标签覆盖,这是我不希望的。
Stackblitz 示例:https ://stackblitz.com/edit/angular-qlpnim-vyfruq
我尝试用属性绑定替换它,但没有成功。我仍然需要它,<mat-label>以便它在视觉上与表单中的其他表单字段相似。
angular ×8
anchor ×1
angular-ivy ×1
angular9 ×1
azure-devops ×1
flutter ×1
flutter-web ×1
hover ×1
html ×1
ivy ×1
javascript ×1
rxjs ×1
tfs ×1
validation ×1