【发布时间】:2016-11-02 06:20:55
【问题描述】:
我有一个简单的用户界面
<button
md-icon-button
md-tooltip = 'Home'
[routerLink] = "['new-patient']">
<i class = 'mdi mdi-home mdi-36px cyanish'></i>
</button>
上面的 routerLink 绑定失败,总是失败并显示以下内容:
Can't bind to 'routerLink' since it isn't a known property of 'a'. ("
<a md-icon-button
[ERROR ->][routerLink] = "['new-patient']"
color = "accent">
<md-icon class = "material-icons md-2"): SideNavsComponent@43:7
我理解这个错误,但我有什么方法可以将 routerLink 实际添加到 material2 按钮或按钮图标?
很难接受这么简单的程序似乎是不可能的。
我之前问过这个问题并得到了一个在 2016 年 6 月有效的答案 - 该答案不再有效 (How to use material2 toolbar, button and angular-cli router)
谢谢
【问题讨论】:
-
在你想使用
routerLink的模块中添加RouterModule就足够了,比如@NgModule({imports: [CommonModule, RouterModule]}) class MyModule {} -
谢谢甘特。有趣的是,该错误没有提示缺少模块。
-
这是一个一般性错误。如果您收到
Can't bind to 'xxx',则表明 Angular 没有在该元素上实例化组件或指令,该元素具有要绑定到该名称的输入。如果名称(xxx,或元素名称)没有拼写错误,则原因是当前模块无法使用组件或指令。这不是特定于routerLink,而是适用于每个组件或指令。 -
感谢冈特的精彩解释。从现在开始会有很大的帮助。
-
嘿@GünterZöchbauer,您想添加它作为答案吗?
标签: angular angular-material2 angular2-router3