本文介绍了angular2中的颜色选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在angular2中使用颜色选择器.我尝试使用npm angular2-color-picker 库.但是在包含该指令后,我只能看到空白屏幕. (在控制台中未找到错误).请帮助我了解我要去哪里哪里,或者让我知道是否还有其他可供选择的angular2库.在此先感谢.

I want to use a color picker in angular2. I tried using npm angular2-color-picker library. But i could see only a blank screen after including the directive. (No error found in console). Please help me by knowing where i am going wrong or let me know whether there is any other angular2 library available for color picking.Thanks in advance.

我的HTML包括:

<div>
<label>Primary</label>
<input [(colorPicker)]="color" [style.background]="color" [value]="color"/>
</div>

我的TS:(AppComponent页面路由到DesignPage)

My TS: (AppComponent page routes to DesignPage)

import {Component, OnInit} from 'angular2/core';
import {ColorPickerDirective} from 'angular2-color-picker/app/color-picker/color-picker.directive';
@Component({
    selector: 'my-design',
    templateUrl: 'wwwWeb/build/component/design/design.html',
    directives: [ColorPickerDirective]
})
export class DesignPage implements OnInit {
 private color: string = "#127bdc";
}

我的Boot.ts

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
import {ColorPickerService} from './color-picker/color-picker.service'

bootstrap(AppComponent, [ColorPickerService]);

我的Tsconfig

My Tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "../node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

推荐答案

您需要通过以下方式配置库:

You need to configure the library this way:

System.config({
  map: {
    'angular2-color-picker': 'node_modules/angular2-color-picker'
  },
  packages: {
    (...)
    'angular2-color-picker': {
      format: 'register',
      defaultExtension: 'js'
    }
  }
});

这篇关于angular2中的颜色选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 04:03