Angular 2 个错误 "Unhandled Promise rejection: Template parse errors:"
Angular 2 error "Unhandled Promise rejection: Template parse errors:"
当我像这样使用 ngClass
指令时:
[ngClass]="{has-error: !myInput.valid}"
我收到以下错误:
Unhandled Promise rejection: Template parse errors:
Parser Error:
Missing expected : at column 5 in [{has-error: !myInput.valid}] in
...html...
如何解决这个错误?
问题出在 has-error
class 名称中的 -
(破折号)字符。
如果您的 class 名字中有破折号,您必须使用这样的引号:
[ngClass]="{'has-error': !myInput.valid}"
当我像这样使用 ngClass
指令时:
[ngClass]="{has-error: !myInput.valid}"
我收到以下错误:
Unhandled Promise rejection: Template parse errors: Parser Error: Missing expected : at column 5 in [{has-error: !myInput.valid}] in ...html...
如何解决这个错误?
问题出在 has-error
class 名称中的 -
(破折号)字符。
如果您的 class 名字中有破折号,您必须使用这样的引号:
[ngClass]="{'has-error': !myInput.valid}"