我正在使用这种方法来获取数据:
home.service.ts
getHomes(): Observable<HomeApi> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'token': `${this.global.token}`
})
};
return this.http.get<HomeApi>('url', httpOptions);
}
Run Code Online (Sandbox Code Playgroud)
home.component.ts
ngOnInit() {
this.service.getHomes().subscribe((res: HomeApi) => this.home = {
images: res['images']
});
}
Run Code Online (Sandbox Code Playgroud)
主页.component.html
getHomes(): Observable<HomeApi> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'token': `${this.global.token}`
})
};
return this.http.get<HomeApi>('url', httpOptions);
}
Run Code Online (Sandbox Code Playgroud)
现在item.name工作得很好,但在控制台中抛出此错误:
错误类型错误:无法读取未定义的属性“图像”
这是示例
我正在学习一个教程,以便在 Angular 中执行异步验证。我想要实现的是我的自定义验证器,它shouldBeUnique应该在 2 秒延迟后调用。我在其中使用setTimeout函数,但它不起作用。甚至错误消息未显示在 div 中。
这是我的自定义验证错误文件。
import { AbstractControl, ValidationErrors } from '@angular/forms';
export class UsernameValidator {
static cannotContainSpace(control: AbstractControl): ValidationErrors | null {
if ((control.value as string).indexOf(' ') >= 0 ) {
return { cannotContainSpace: true };
}
return null;
}
static shouldBeUnique(control: AbstractControl): Promise<ValidationErrors | null> {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (control.value === 'bilal') {
resolve({shouldBeUnique: true});
} else {
resolve(null);
}
}, 2000);
});
} …Run Code Online (Sandbox Code Playgroud) 如何在 React 应用程序中使用 angular 6 组件。
我创建了一个 angular 组件并创建了一个分布式包,我可以在另一个 angular 项目中使用它,我如何在 react js 应用程序中使用相同的组件。
谢谢,斯里尼瓦斯
我需要使用反应式 angular 4+ 检查密码和确认密码字段是否具有相同的值。我确实在这里看到了很多相同的答案,Angular 4 表单验证重复密码,将验证器中的字段与 angular 4 进行比较,但似乎没有一个对我有用。
面对问题,如何在反应式方法中结合确认电子邮件和确认密码验证器。
确认电子邮件或确认密码工作正常。
this.addEmpForm = new FormGroup({
'name': new FormControl(null, Validators.required),
'email': new FormControl(null, [Validators.required, Validators.email]),
'cemail': new FormControl(null, [Validators.required, Validators.email]),
'password': new FormControl(null, Validators.required),
'cpassword': new FormControl(null, Validators.required)
}, this.pwdMatchValidator);
}
emailMatchValidator(frm: FormGroup) {
return frm.get('password').value === frm.get('cpassword').value
? null : { 'mismatch': true };
}
pwdMatchValidator(frm: FormGroup) {
return frm.get('password').value === frm.get('cpassword').value
? null : { 'mismatch': true };
}
Run Code Online (Sandbox Code Playgroud)
HTML
<span class="help-block"
*ngIf="addEmpForm.get('cemail').touched && cemail?.errors ||
addEmpForm.get('cemail').touched && addEmpForm.errors?.mismatch"> …Run Code Online (Sandbox Code Playgroud) 我的应用程序错误 TS2339 中出现错误:“Observable”类型上不存在属性“过滤器” 我的组件 ts 文件
import { Component, OnInit } from '@angular/core';
import {
Router,
ActivatedRoute,
NavigationEnd,
Params,
PRIMARY_OUTLET
} from '@angular/router';
import 'rxjs/add/operator/filter';
ngOnInit() {
const ROUTE_DATA_BREADCRUMB: string = 'breadcrumb';
//subscribe to the NavigationEnd event
this.router.events
.filter(event => event instanceof NavigationEnd)
.subscribe(event => {
//set breadcrumbs
let root: ActivatedRoute = this.activatedRoute.root;
this.breadcrumbs = this.getBreadcrumbs(root);
console.log(this.breadcrumbs);
});
}
Run Code Online (Sandbox Code Playgroud)
我的 package.json
"dependencies": {
"@agm/core": "^1.0.0-beta.5",
"@angular/animations": "^6.1.8",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": …Run Code Online (Sandbox Code Playgroud) 我有 angular 6 项目。我同时使用了 ngModel 和 formControlName。但是 angular 在下面给了我警告。例如,当我从网格中的按钮打开更新弹出窗口时,我可以轻松地自动绑定更新弹出窗口中的输入。但是 angular 7 说删除 ngModel。因此,我必须始终将所有内容映射到我的学生对象。最好的方法是什么?我们可以在下面的代码中给 formValueType 像 studentObject 这样的表单值,然后它可以自动绑定吗?
角度警告:
It looks like you're using ngModel on the same form field
as formControlName. Support for using the ngModel input property and
ngModelChange event with reactive form directives has been deprecated
in Angular v6 and will be removed in Angular v7.
Run Code Online (Sandbox Code Playgroud)
我的HTML
<form [formGroup]="studentForm" ??????formValueType="studentObject"?????>
<p-dialog>
<div class="ui-g-12 form-group">
<div class="ui-g-4">
<label>Name Surname</label>
</div>
<div class="ui-g-8">
<input pInputText [(ngModel)]="selectedStudent.nameSurname" formControlName="nameSurname" />
</div>
</div> …Run Code Online (Sandbox Code Playgroud) Angular 4 中是否有任何现在在 Angular 6 中已过时的功能?或者换句话说,我可以在我的应用程序中使用 angular 6 库并使用其中的所有 Angular 4 功能。我是 Angular 框架的新手,只是想知道我应该直接从 Angular 6 开始还是应该先阅读 Angular 4。
我的代码
<ngx-datatable
#table
[columnMode]="'force'"
[headerHeight]="50"
[rowHeight]="'auto'"
[footerHeight]="50"
[count]="true"
[limit]="4"
[rows]="data"
>
<ngx-datatable-column [width]=10>
<ng-template let-row="row" ngx-datatable-cell-template>
<span class="circle" [ngClass]="{'red': row.alertCat == 'HIGH','yellow': row.alertCat == 'MEDIUM', 'green': row.alertCat == 'LOW'}"></span>
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column name="ID" [width]=10>
<ng-template let-column="column" ngx-datatable-header-template>
<strong class="text-uppercase alertHeading">ID</strong>
</ng-template>
<ng-template let-row="row">
{{row.id}}
</ng-template>
</ngx-datatable-column>
</ngx-datatable>
Run Code Online (Sandbox Code Playgroud)