无法绑定到颜色,因为它不是“按钮”

时间:2016-10-07 23:31:05

标签: angular

错误

Can't bind to color since it isn't a known property of 'button'.

代码

@Component({
    selector: "nav-next",
    template: `
    <div class="nav-next-directive">
        <button [color]="color" class="primary" [
        </button>
    </div>`
})

预期行为

这个子指令使我们Angular2-RC4能够从父组件动态设置颜色。 Angular2-Final表示这不好。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

首次亮相ngModule后,您必须在使用之前将Directive添加到ngModule declarations数组中:

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ App, ColorDirective ],
  bootstrap: [ App ]
})
export class AppModule {}

并确保您的Directive selector属于属性类型:

@Directive({
  selector: "[color]"
})

以下是工作示例,如果您更改上述两项中的任何一项,您将收到该错误:http://plnkr.co/edit/ymUTyuMo9FsSORd9XI2H?p=preview