2017-04-27 31 views
0

我正在使用angular-cli和bootstrap-colorpicker。我想从colorPicker onchange/oninput方法中获取颜色。如何使用bootstrap-colorpicker在angular2上获取更改值或输入方法?

这里是我的html代码:

<div id="cp2" class="input-group colorpicker-component"> 
    <input id="colorInput" type="text" value="#00AABB" class="form-control textedit" data-type="color" (input)="testevent($event)" /> 
    <span class="input-group-addon"><i></i></span> 
</div> 
在TS文件

testevent(event){ 
    console.log(event.target.value); 
} 

此功能,当我在输入类型直接进行输入工作。使用jQuery方法onchange或oninput我能够获得价值。但我想用angular2的方式。

请建议我解决这种情况。

感谢和问候

回答

0

您可以使用[(ngModel)]就像任何其它的输入

<input id="colorInput" type="text" 
    [(ngModel)]="colorCode" 
     value="#00AABB" 
     class="form-control textedit" 
     data-type="color" (change)="test()" /> 


test(){ 
    console.log(this.colorCode); 
}