typescript 无法绑定到“ngClass”,因为它不是“button”的已知属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40902835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't bind to 'ngClass' since it isn't a known property of 'button'
提问by BentOnCoding
HTML:
HTML:
<button class="sa-button" [ngClass]="'buttonClass'">{{displayText}}</button>
The variable I expect to bind to in my typescript file:
我希望在打字稿文件中绑定的变量:
public buttonClass = "button";
The error I get:
我得到的错误:
Can't bind to 'ngClass' since it isn't a known property of 'button'
无法绑定到“ngClass”,因为它不是“button”的已知属性
I want to bind a variable which holds the name of the css class I want to apply.
我想绑定一个变量,该变量包含我要应用的 css 类的名称。
Is there a correct way to do this? I literally copied this out of the angular docs, and it doesn't work.
有没有正确的方法来做到这一点?我真的从 angular 文档中复制了这个,但它不起作用。