首页 > 解决方案 > AngularTS如何将HTML中的输入变量设置为真/假?

问题描述

我有html:

<tag-input fullWidth id="inputDir" formControlName="inputDir" [modelAsStrings]="true"
                            [placeholder]="'choice feature'"
                            [allowDupes]="falseVariable"
                            [secondaryPlaceholder]="'choice feature'">
                            <tag-input-dropdown [showDropdownIfEmpty]="true" [autocompleteItems]="inputDirAutoComplete">
                            </tag-input-dropdown>

</tag-input>

我想设置allowDupes为假。当我设置为时它起作用了,falseVariable我在 .ts 中给出了错误值

falseVariable = false;

但是,如果我将 false 设置为 HTML,它就不起作用

<tag-input fullWidth id="inputDir" formControlName="inputDir" [modelAsStrings]="true"
                            [placeholder]="'choice feature'"
                            [allowDupes]="'false'"
                            [secondaryPlaceholder]="'choice feature'">
                            <tag-input-dropdown [showDropdownIfEmpty]="true" [autocompleteItems]="inputDirAutoComplete">
                            </tag-input-dropdown>

</tag-input>

我错过了什么 ?

(示例中的库是import { TagInputModule } from 'ngx-chips';

标签: htmlangulartypescript

解决方案


allowDupes是一个布尔变量,不是string变量。

在第二个代码片段上,您分配string了变量而不是boolean变量。

请更换[allowDupes]="'false'"[allowDupes]="false",它会工作。


推荐阅读