标签: angular-template-variable

ngFor - 无法绑定到“testid”,因为它不是“input”的已知属性。如何将 id 与字符串连接起来?

我正在尝试用我的 ID 添加index值。但出现错误:

Can't bind to 'testid' since it isn't a known property of 'input'.
Run Code Online (Sandbox Code Playgroud)

这是我的模板:

<td *ngFor="let col of columns; let i = index"  [ngClass]="col.class" data-testid="form-create-td-{{i}}">
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题吗?有人帮助我吗?

angular angular-template-variable angular8 angular-testing-library

8
推荐指数
1
解决办法
3374
查看次数

从 Angular 中的模板引用变量获取 ElementRef

在下面的代码中

<input #myRef1 />
<input #myRef2 my-custom-attribute />
Run Code Online (Sandbox Code Playgroud)

将会#myRef1是一个ElementRef, 并且#myRef2将会是MyCustomAttributeComponent指令性的。基本上,它隐式地找到第一个组件并将其关联到模板引用变量。我可以强制我想要哪个指令/组件,这要归功于exportAs,但在这里,我实际上在两种情况下都想要ElementRef

有没有什么东西可以强制#myRef2成为一个ElementRef 没有TypeScript的东西@ViewChild(..., { read: ElementRef })。我需要在我的模板中myRef2作为 an进行访问ElementRef

angular angular-template-variable

5
推荐指数
1
解决办法
3463
查看次数

角度参考 # 与 ngModel

我想知道什么时候我必须在我的输入中使用 [(ngModel)] 以及什么时候我可以只使用 #reference 例如

<div class="form-group">
  <div class="input-group mb-2">
    <input type="text" class="form-control" [(ngModel)]="newUser">
    <button class="btn btn-outline-success" (click)="onAddUser()">Add user</button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我应该在这里这样做,或者我可以这样做:

<div class="form-group">
  <div class="input-group mb-2">
    <input type="text" class="form-control" #newUser>
    <button class="btn btn-outline-success" (click)="onAddUser(newUser.value)">
      Add user
    </button>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我将不胜感激任何答案)

angular-ngmodel angular angular-template-variable

4
推荐指数
2
解决办法
3655
查看次数

为模板中的变量赋值 - Angular7

有两个切换按钮(编辑和提交),哪个按钮应该像点击时切换显示/隐藏样式一样工作

<button (click)="showEditBtn = false;" *ngIf="showEditBtn;"> Edit</button>
<button (click)="showEditBtn =  true;" *ngIf="!showEditBtn;">Submit</button> 
Run Code Online (Sandbox Code Playgroud)

我需要 showEditBtn变量应该是true默认值而不触及脚本文件

是否可以为模板中的变量赋值,如下例所示?

<div> {{  let showEditBtn = true  }}  </div>
Run Code Online (Sandbox Code Playgroud)

堆叠闪电战示例

javascript variables angular angular-template-variable angular7

4
推荐指数
1
解决办法
9823
查看次数