将鼠标悬停在表中的第一列上时,会出现一个工具提示,单击按钮会打开包含编辑 json 部分的对话框。
我提供了 2 个功能:-
[请从对话框的左侧部分选择一行]
1) 可以编辑 json(在这种情况下,用户单击左侧部分的行,开始编辑 json,并且在不恢复新更改的情况下,用户单击左侧部分下的不同行,然后再次选择先前选择的行原始 json数据被保留)
2) 用户单击左侧部分的行,并开始从输入字段提供输入(出现在“添加为”按钮上方)我开始更新“编辑 Json”部分中的“mTitle”键,因此一旦用户点击另一个行并再次返回到先前选择的行,json 'mTitle' 键不显示原始(旧)值
预期行为
我期待的是一旦用户提供输入,'mTitle' 键应该被更新(这是有效的)但是在 Add As New 按钮被点击或用户点击后,'mTitle' 键应该再次保留其旧值在另一行。(与情况 1 相同的行为)
Stackblitz 链接 https://stackblitz.com/edit/angular-mat-tooltip-v6m2tz?file=app%2Falert-dialog%2Falert-dialog.component.ts
请建议
警报对话框.component.html
<form [formGroup]="jsonform">
<json-input formControlName="json" name="result"></json-input>
</form>
<form [formGroup]="submitJsonNameAndForm" class="">
<mat-form-field [floatLabel]="'never'" class="alertinput">
<input matInput trim type="text" #alertnamefieldRef formControlName="alertnamefield" placeholder="Custom Alert Name"
autocomplete="off" (keyup) = "passingAlerTitle(alertnamefieldRef?.value)">
</mat-form-field>
</form>
Run Code Online (Sandbox Code Playgroud)
警报对话框.component.ts
passingAlerTitle(event){
this.data.data[this.selectedId].conditionals.alert.mTitle = event;
this.jsonform.setValue({
json: this.data.data[this.selectedId].conditionals
});
}
Run Code Online (Sandbox Code Playgroud) 当前,用户只能使用“材料” create和“ done图标”作为步骤标题。这些更改提供了通过提供ng-template覆盖来自定义图标的功能。所以我找到了更新,
但是当我将其用作
<mat-horizontal-stepper [linear]="isLinear">
<mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Fill out your name</ng-template>
<ng-template matStepperIcon="edit">
<custom-icon>edit</custom-icon>
</ng-template>
<mat-form-field>
<input matInput placeholder="Last name, First name" formControlName="firstCtrl" required>
</mat-form-field>
<div>
<button mat-button matStepperNext>Next</button>
</div>
</form>
</mat-step>
<mat-step>
<ng-template matStepLabel>Done</ng-template>
You are now done.
<div>
<button mat-button matStepperPrevious>Back</button>
</div>
</mat-step>
</mat-horizontal-stepper>
Run Code Online (Sandbox Code Playgroud)
我得到这个错误
Uncaught Error: Template parse errors:
'custom-icon' is not a known element:
1. If 'custom-icon' is an Angular component, then verify that it is part …Run Code Online (Sandbox Code Playgroud) 我写下了代码来计算字符串中每个字符的计数。对于某些失败的单词,它似乎正常工作。
对于最后一个字符,它失败,因为我看到字符串的长度变得小于迭代计数(但对于某些单词)
var str1 = "america"
function noofchars(str1) {
for (var m = 0; m < str1.length + 1; m++) {
var countno = 1;
if (m != 0) {
str1 = str1.slice(1)
}
str2 = str1.substr(0, 1)
for (var i = 0; i < str1.length; i++) {
if (str2 === str1.charAt(i + 1)) {
countno += 1
str1 = str1.slice(0, i + 1) + str1.slice(i + 2) + " "
}
}
console.log(str1.charAt(0) + "=" + countno)
}
} …Run Code Online (Sandbox Code Playgroud)我想以 json 格式在工具提示中显示数据,如图所示。
我可以在工具提示中加载数据(但不能按照所附图片中的格式)。
<ng-container matColumnDef="Alert">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Alert </th>
<td mat-cell *matCellDef="let row">
<span matTooltip="{{(row?.conditionals)?(row.conditionals | json):''}}">{{row.Alert}}</span>
</td>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
堆栈闪电战链接。html 和 ts 代码位于 stackblitz 链接中。
https://stackblitz.com/edit/angular-mat-tooltip-xngsaq?file=app%2Ftooltip-overview-example.ts
当我们将鼠标悬停在第一列时,在工具提示条件、偏移、警报中需要显示如附图所示。
#EDIT1 我还尝试过基本的 html 工具提示,如果有人可以建议格式化数据,这也对我有用
https://stackblitz.com/edit/angular-mat-tooltip-ik3f8e?file=app%2Ftooltip-overview-example.css
作为参考,so 链接之一 使用 JavaScript 进行漂亮打印 JSON