Angular Font Picker
This is a simple font picker loosely based on the cool angular2-color-picker by Alberplz.
This documentation is for the latest 5/6.x.x version which requires Angular 5 or newer. For Angular 4 you need to use the latest 4.x.x version. Documentation for the 4.x.x can be found from here.
Quick links
Example application
|
StackBlitz example
Building the library
npm install
npm run build
Running the example
npm install
npm run start
Installing and usage
npm install ngx-font-picker --save
Load the module for your app (with global configuration):
Global configuration should be provided only once (this is usually done in the root module).
import { FontPickerModule } from 'ngx-font-picker';
import { FONT_PICKER_CONFIG } from 'ngx-font-picker';
import { FontPickerConfigInterface } from 'ngx-font-picker';
const DEFAULT_FONT_PICKER_CONFIG: FontPickerConfigInterface = {
apiKey: 'AIzaSyA9S7DY0khhn9JYcfyRWb1F6Rd2rwtF_mA'
};
@NgModule({
...
imports: [
...
FontPickerModule
],
providers: [
{
provide: FONT_PICKER_CONFIG,
useValue: DEFAULT_FONT_PICKER_CONFIG
}
]
})
Use it in your HTML template (for example in div element):
<div #fontPickerElement=ngxFontPicker [(fontPicker)]="font" [fpWidth]="'320px'" [fpPosition]="'bottom'">
Click to open the font picker
</div>
[(fontPicker)]
[fpWidth]
[fpHeight]
[fpPosition]
[fpAutoLoad]
[fpSearchText]
[fpLoadingText]
[fpPopularLabel]
[fpResultsLabel]
[fpSizeSelect]
[fpStyleSelect]
[fpPresetLabel]
[fpPresetFonts]
[fpPresetNotice]
[fpFallbackFont]
[fpCancelButton]
[fpCancelButtonText]
[fpCancelButtonClass]
[fpUploadButton]
[fbUploadButtonText]
[fpUploadButtonClass]
[fpDialogDisplay]
[fpUseRootViewContainer]
(fontPickerChange)
(fontPickerUpload)
Available configuration options (for the global configuration):
apiKey
Available control / helper functions (provided by the service):
loadFont(font)
getAllFonts(sort)
Available control / helper functions (provided by the directive):
loadFont(font)
openDialog()
closeDialog()
toggleDialog()
Accessing the Font Picker directive by using a ViewChild reference:
@ViewChild('fontPickerElement', {static: true})
fontPicker: FontPickerDirective;
closeFontPicker(field: string): void {
this.fontPicker.closeDialog();
}