在Angular 2中添加jQuery-Knob

时间:2017-11-13 13:24:56

标签: angular aspnetboilerplate jquery-knob

我是Angular 2.0新手并使用aspnetboilerplate模板。

我正在尝试整合jQuery-Knob

首先,我在jquery.knob.min.js中的scripts中添加了.angular-cli.json

"scripts": 
[
    "../src/bsb-theme/js/jquery.validate.js",
    "../src/bsb-theme/js/jquery.knob.min.js"
]

然后,我在input中发了dashboard.component.html

<input type="text" class="knob" value="40"
    data-width="125"
    data-height="125"
    data-thickness="0.25"
    data-angleArc="250"
    data-angleoffset="-35"
    data-fgColor="#00BCD4">

但输出只是一个文本框。

1 个答案:

答案 0 :(得分:1)

jQuery-Knob无法与Angular 2一起使用。

试试此库:https://github.com/xzegga/angular2-knob

用法

导入角度模块:

import { KnobModule } from "angular2-knob";

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [KnobModule]
  bootstrap: [AppComponent]
})

HTML使用:

<div ui-knob [value]="value" [options]="knOptions"></div>

在角线组件中配置选项:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{
  knOptions = {
    readOnly: true,
    size: 140,
    unit: '%',
    textColor: '#000000',
    fontSize: '32',
    fontWeigth: '700',
    fontFamily: 'Roboto',
    valueformat: 'percent',
    value: 0,
    max: 100
    trackWidth: 19,
    barWidth: 20,
    trackColor: '#D8D8D8',
    barColor: '#FF6F17',
    subText: {
      enabled: true,
      fontFamily: 'Verdana',
      font: '14',
      fontWeight: 'bold',
      text: 'Overall',
      color: '#000000',
      offset: 7
    },
  }
  value = 45; 
}