我有以下 Angular 7 形式:
ngOnInit() {
this.organizationId = 1; // Used for testing
this.form = this.formBuilder.group({
name: [''],
organizationId: [{ value: this.organizationId, disabled: this.enableOrganizationChange }],
start: ['']
});
}
Run Code Online (Sandbox Code Playgroud)
在 HTML 中我使用的是Selectfor OrganizationId。它按预期被禁用。
然而,提交时该值null不是 1:
onSubmit() {
if (this.form.valid) {
this.submitting = true;
console.log(this.form.value.organizationId);
let request: Request = {
name: this.form.value.name,
organizationId: this.form.value.organizationId.value,
start: this.form.value.start
};
}
}
Run Code Online (Sandbox Code Playgroud)
为什么记录的值是null而不是1?
我使用禁用只是为了避免用户更改值。
但我仍然需要提交时的值...
可以单击步骤标题来选择时间波纹即将到来的步骤我想从该步进器中删除或禁用波纹。
<mat-vertical-stepper>
<mat-step label="Step 1">
Content 1
</mat-step>
<mat-step label="Step 1">
Content 2
</mat-step>
</mat-vertical-stepper>
Run Code Online (Sandbox Code Playgroud)
还请解释一下这个属性是如何工作的。是否应禁用步骤标题的波纹。
@Input()
disableRipple: boolean
Run Code Online (Sandbox Code Playgroud) 我使用 ngFor 生成了多个离子幻灯片,并在那里插入了一个组件。它多次调用 ngOnChanges。我希望它只调用一次,以便我可以调用我的 api。
我尝试过使用多个角度生命周期挂钩。
这就是我创建幻灯片的方式,菜单有 19 个元素
<ion-slides #slides [options]="slideOpts" (ionSlideDidChange)="slideChanged($event)">
<ion-slide *ngFor="let i of menu; let j = index">
<h1>{{ i.name }}</h1>
<app-homenews [categoryId]="currentCategoryId" ></app-homenews>
</ion-slide>
</ion-slides>
Run Code Online (Sandbox Code Playgroud)
这就是我们进行变更检测的方式
@Input() categoryId: number;
ngOnChanges(changes: SimpleChanges) {
let chg = changes['categoryId'];
console.log(chg.currentValue);
}
Run Code Online (Sandbox Code Playgroud)
我希望它只被调用一次,现在它已经调用了 19 次。
我可以在这里使用 rxjs 吗?
从文档示例中,我尝试使用 mat 表导出器,如下所示:
<ng-container>
<mat-card class="mat-card py-0">
<mat-card-header class="label">
<ng-container>
<mat-card-title>{{titoloTabella}}</mat-card-title>
<button mat-button class="align-right" (click)="changeClass()">
<mat-icon [ngClass]="(rotate)?'rotate':'no-rotate'">keyboard_arrow_down</mat-icon>
</button>
</ng-container>
</mat-card-header>
<table mat-table matSort [dataSource]="dataSource" matTableExporter #exporter="matTableExporter">
<ng-container *ngFor="let header of tableConfiguration.tableHeaders; let i = index" matColumnDef="{{ header.headerId }}">
<th mat-header-cell mat-sort-header *matHeaderCellDef>{{ header.headerName }}</th>
<td mat-cell *matCellDef="let row" > {{ row[header.headerId] }} </td>
<ng-container *ngIf="i == 0 && header.isJoinable == 'no'">
<td mat-footer-cell *matFooterCellDef>TOTALE</td>
</ng-container>
<ng-container *ngIf="i > 0">
<td mat-footer-cell *matFooterCellDef>{{ tableFooter[header.headerId] }}</td>
</ng-container>
</ng-container>
<tr mat-header-row …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据从 Component.ts 获取的值来禁用输入
在我的component.ts文件中我有这个值
disName = false;
Run Code Online (Sandbox Code Playgroud)
在我的 HTML 中我有这些元素
Name: <input type="text"
value="name"
size="15"
id="name"
name="firstName"
[(ngModel)]="aproverFirstName"
[attr.disable]="disName=='true' ? true : null">
Run Code Online (Sandbox Code Playgroud)
寻找的是,如果我的值是component.tsfalse,那么在 html 文件中,输入元素应该根据该值更改为禁用。
我也尝试过这个[disable]="disName"
我正在使用 Angular 7,非常感谢!
我有一个菜单项列表,我想将数组中的最后一项设为链接。
现在,菜单项是从组件构建的,但我不确定如何使数组中的最后一项成为链接。
ActionMenuItem.component.html
<div *ngIf="expanded">
<actionmenuitem *ngFor="let child of line.children" [line]="child" (inWorkspace)="toWorkspace($event)"></actionmenuitem>
Run Code Online (Sandbox Code Playgroud)
ActionMenuItem.Component.ts
onSelect(){
// If it has children, expand them && flip carat.
if(this.line.children.length > 0){
this.expanded = !this.expanded;
if(this.iconName == "expand_more"){
this.iconName = "expand_less"
} else {
this.iconName = "expand_more"
}
} else {
this.inWorkspace.emit(this.line);
}
Run Code Online (Sandbox Code Playgroud) 如标题所述,我们是否需要为模块手动实现延迟加载,还是Angular 6/7默认执行?
我正在尝试使用* OR来获取* ngIf,但是第二个选项将被忽略。
这是代码:
<div *ngIf="router.url != '/one' || router.url != '/two'">
show something
</div>
Run Code Online (Sandbox Code Playgroud)
我该如何工作?
我已将项目从Angular 4升级到Angular 7,并且出现以下错误:
node_modules/@ng-bootstrap/ng-bootstrap/typeahead/typeahead.d.ts(3,10)中的错误:错误TS2305:模块'“ D:/ usman / dev_area / code / physician-portal / node_modules / rxjs / Observable “”没有导出成员“可观察”
node_modules / rxjs / Observable.d.ts(1,15):错误TS2307:找不到模块'rxjs-compat / Observable
在这里输入图像描述我最近向package.JSON添加了一些依赖项,并尝试安装npm。但它显示与git相关的错误,也找不到
npm ERR!路径git
npm错误!代码ENOENT
npm ERR!errno ENOENT
npm ERR!syscall生成git
npm ERR!enoent执行时出错:
npm ERR!enoent未定义ls-remote -h -t ssh://git@github.com/eligrey/FileSaver.js.git
npm ERR!enoent
npm ERR!enoent
npm ERR!enoent生成git ENOENT
npm ERR!enoent这与npm无法找到文件有关。npm ERR!enoent
npm ERR!可以在以下位置找到此运行的完整日志: