首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角度输入HyperLinks

角度输入HyperLinks
EN

Stack Overflow用户
提问于 2021-07-12 06:21:22
回答 1查看 680关注 0票数 2

在我的代码中,我有一个输入字段,用户可以在其中输入一些内容。当用户输入并按下“完成”时,我希望输入是一个超链接。这是我的密码。我应该添加什么来使输入成为一个链接?

HTML:

代码语言:javascript
复制
<ng-container matColumnDef="FilePath" #filePath>
                                <th mat-header-cell *matHeaderCellDef> Dosya Yolu </th>
                                <td mat-cell *matCellDef="let row; let i = index">
                                    <span *ngIf="EditIndex != i">{{row.LabAnalysisFiles.FilePath}}</span>
                                    <mat-form-field floatLabel="never" *ngIf="EditIndex == i" class="w-100-p">
                                        <input matInput name="FilePath" [(ngModel)]="row.LabAnalysisFiles.FilePath" type="text">
                                    </mat-form-field>
                                </td>
                            </ng-container>

                            <ng-container matColumnDef="Actions">
                                <th mat-header-cell *matHeaderCellDef></th>
                                <td mat-cell *matCellDef="let row; let i = index">
                                    <div *ngIf="!isClosed">
                                        <button mat-icon-button *ngIf="EditIndex != i" (click)="editRow(row, i)">
                                            <mat-icon>edit</mat-icon>
                                        </button>
                                        <button mat-icon-button *ngIf="EditIndex == i"
                                            (click)="editRow(row, undefined)">
                                            <mat-icon>done</mat-icon>
                                        </button>

                                    </div>
                                </td>
                            </ng-container>
TS:


 testList: ILabConditionResult[] = [];
    filePath: ILabAnalysisFile;
        editRow(row: ILabConditionResult, index: number) {
            if (index == undefined) {
                if (
                    !row.LabAnalysisFiles.FilePath
                ) {
                    return;
                }
                this.testList = [];
            } else {
                this.testList = [];
            }
            this.EditIndex = index;
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-12 06:29:44

要使文本显示为超链接,必须使用a标记和href属性。

因此,在代码中,您必须更改

代码语言:javascript
复制
<span *ngIf="EditIndex != i">{{row.LabAnalysisFiles.FilePath}}</span>

代码语言:javascript
复制
<a href *ngIf="EditIndex != i">{{row.LabAnalysisFiles.FilePath}}</a>

请记住,如果单击链接,它将导航,因此,如果不需要此行为,则应添加:

代码语言:javascript
复制
(click)="$event.preventDefault()"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68342714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档