我在 Angular 5 中使用 FormData,但它给出了下面给出的错误。
approvalUser(userId): Observable<any> {
let formData = new FormData();
formData = formData.append('id',userId); error in this line shows==> "Type 'void' is not assignable to type 'FormData' "
return this.http.post<any>(this.url.APPOROVAL_USER,formData);
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个新的angular5项目,我正在使用角度材料作为前端组件(https://material.angular.io/
).一切都很好,但主要的问题是如何添加自定义主题.我没有在这个项目上使用scss编译器,所以我正在做的是将所有css组件导入到style.css中
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
@import "~app/components/test/test.component.css";
Run Code Online (Sandbox Code Playgroud)
问题是我不知道如何修改预建主题的基色或为我的主题生成另一种基色的css.如果有人可以帮助我,我会非常感激!
在 angular 4 中,我使用 *ngFor 来显示一些图像
<div *ngFor='let image of images;let i = index'>
<img [src]="'/assets/Images/'+image+'.png'" *ngIf="!tohide(i,0);">
</div>
Run Code Online (Sandbox Code Playgroud)
第一次完成 *ngFor 后,我希望通过 *ngIf 删除特定图像,而不更改数组“图像”。问题是每当我使用我的函数“tohide”删除图像时,*ngFor 再次绑定到“图像”并更新图像集。
换句话说,有没有办法强制 *ngFor 偶尔不听数组“图像”?
我有以下代码无法正常工作.
我有一项服务,为用户提供注册.
register(firstname: string, lastname: string, email: string, password: string): Observable<boolean> {
let body = {firstname: firstname, lastname: lastname, email: email, password: password};
this.http.post(this.base_url + "api/register/user/", body)
.subscribe(
(data) => {
if((data as any).status == 'success') {
return Observable.of(true);
}
},
(error) => {
return Observable.of(false);
});
return Observable.of(false);
}
Run Code Online (Sandbox Code Playgroud)
注册方法工作正常,因为我注册用户的API返回"成功".问题是当我调用它时如下:
registerUser(e) {
...
let isRegistered = false;
this.userService.register(firstname, lastname, email, password).subscribe(register => isRegistered = register);
if(isRegistered) {
console.log("isRegistered = true");
this.router.navigate(['/home']);
return true;
} else {
console.log("isRegistered = false"); …
Run Code Online (Sandbox Code Playgroud) 我正在使用角材料。
问题出在mat-select
. 它不绑定记录编辑时的值。
这是我的代码..
HTML
如您所见,我test.subject
在模型中绑定了(一个对象)并subject.title
在下拉列表中显示为文本。
<mat-form-field>
<mat-select [(ngModel)]="test.subject" placeholder="Subject" name="subject">
<mat-option>--</mat-option>
<mat-option *ngFor="let subject of subjects" [value]="subject">
{{subject.title}}
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
成分
在组件中,我从数据库中获取了这个值。
this.test = {
"subject": {
"_id": "5b3883b4067d8d2744871eff",
"title": "Subject 1"
}
}
this.subjects = [
{
"_id": "5b3883b4067d8d2744871eff",
"title": "Subject 1"
},{
"_id": "5b3843b4067d8d2744435erx",
"title": "Subject 2"
}
]
Run Code Online (Sandbox Code Playgroud)
所以在这里我希望下拉菜单应该选择 value Subject 1
。但事实并非如此。
我有一个简单的登录/注销状态管理。我收到此错误:
类型“(state: State | undefined, action: authActions) => State”不可分配给类型“ActionReducer<State, Action>”。参数“action”和“action”的类型不兼容。类型“Action”不可分配给类型“authActions”。类型“操作”不可分配给类型“注销”。属性“type”的类型不兼容。类型“string”不可分配给类型“types.LOGOUT”。
这是我的文件。
授权操作.ts
import { Action } from '@ngrx/store';
import { User } from '../user/user.model';
export enum types {
LOGIN = '[AUTH] LOGIN',
LOGOUT = '[AUTH] LOGOUT',
}
export class Login implements Action {
readonly type = types.LOGIN;
constructor(public payload: User) {}
}
export class Logout implements Action {
readonly type = types.LOGOUT;
}
export type authActions = Login | Logout;
Run Code Online (Sandbox Code Playgroud)
auth.reducer.ts
import { User } from '../user/user.model';
import * as …
Run Code Online (Sandbox Code Playgroud)