javascript - Angular :@input boolean 和 ngIf 不匹配

标签 javascript angular typescript input

(对不起我的英语,这不是我的第一语言......)

当我使用其模板调用它时,我在组件中注入(inject)的一些输入参数存在一些问题。

slider-multiple.component.ts :

import { Component, Input } from '@angular/core';

@Component({
  selector: 'slider-multiple',
  templateUrl: './slider-multiple.component.html'
 })
export class SliderMultipleComponent  {
   @Input() public modifiable: boolean;
 }

slider-multiple.component.html :

<button *ngIf="modifiable">Slider Button</button>

指令的调用(例如在 app.component.html 上):

<slider-multiple modifiable="activation"></slider-multiple>

在 app.component.ts 上定义激活:

export class AppComponent  {
   public activation : boolean = false ;

   public activate(){
     this.activation = !this.activation;
   }
 }

只有当指令的激活参数为 true 时,我在组件的 html 模板上定义的按钮才应该可见(通过 *ngIf)。

有谁知道为什么它不能按预期工作?

A Stackblitz帮助。

提前致谢!

最佳答案

更改 <slider-multiple modifiable="activation"></slider-multiple>

收件人<slider-multiple [modifiable]="activation"></slider-multiple>

modifiable="activation"绑定(bind)到值为 activation 的字符串.

[modifiable]="activation"绑定(bind)到名称为 activation 的组件属性.

关于javascript - Angular :@input boolean 和 ngIf 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49799884/

相关文章:

typescript - 这是什么意思 { 0 : T } in this type declaration?

javascript - 如何在 Electron 中设置 chromium 命令行标志?

javascript - 如何使用类访问数组中的某个索引?

Angular 2 : routeLink does not create href attribute

Angular 6 Material : mat-tab-link be selected by underlining bar

Javascript foreach 和 for 循环总是仅在执行 array.push 时循环一次

javascript - document.getElementByID ("test").innerHTML 给出 TypeError : 'undefined' is not a function (evaluating 'document.getElementByID("test")')

javascript - 如何显示/隐藏谷歌图表的表格单元格内容

javascript - Angular 2+ : Multiple definitions of a property not allowed in strict mode in IE11

angular - 在停止调试时终止 vs 代码中的 ng serve 任务