npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ng-stack/contenteditable

v2.0.1

Published

This is micro Angular v4+ contenteditable directive for integration with Angular forms. It just implements [ControlValueAccessor](https://angular.io/api/forms/ControlValueAccessor) for this purpose.

Downloads

8,332

Readme

What is this library?

This is micro Angular v4+ contenteditable directive for integration with Angular forms. It just implements ControlValueAccessor for this purpose.

Install

npm install @ng-stack/contenteditable --save

Usage

Import and add NgsContenteditableModule to your project:

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgsContenteditableModule } from '@ng-stack/contenteditable';

// ...

@NgModule({
  // ...
  imports: [
    // Import this module to get available work angular with `contenteditable`
    NgsContenteditableModule,
    // Import one or both of this modules
    FormsModule,
    ReactiveFormsModule
  ]

// ...

})

And then you can to use it in template-driven forms or reactive forms like this:

// In your component
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';

export class MyComponent implements OnInit {
  templateDrivenForm = 'This is contenteditable text for template-driven form';
  myControl = new FormControl();

  ngOnInit() {
    this.myControl.setValue(`This is contenteditable text for reactive form`);
  }
}
<form #testForm="ngForm">
  <p
    editable="true"
    name="myFormName"
    [(ngModel)]="templateDrivenForm"
    ></p>
</form>
 
<pre>
  {{ testForm.value | json }}
</pre>

<hr>

<p editable="true" [formControl]="myControl"></p>

<pre>
  {{ myControl.value | json }}
</pre>

Options

propValueAccessor

With editable directive you can pass optional @Input value for propValueAccessor:

<p
  editable="true"
  propValueAccessor="innerHTML"
  [formControl]="myControl"
  ></p>

Internally, ContenteditableDirective uses this value as follows:

this.elementRef.nativeElement[this.propValueAccessor]

By default it using textContent.

editable as @Input property

Since version 2.0.0, @ng-stack/contenteditable accepts editable as @Input property (note the square brackets):

<p [editable]="isContenteditable"></p>

where isContenteditable is a boolean variable.

unformattedPaste

Since version 1.1.0, @ng-stack/contenteditable takes into account experimental unformattedPaste attribute:

<p
  editable="true"
  unformattedPaste
  [formControl]="myControl"
  ></p>

This allow copy formated text (from anywhere) and paste unformated text into HTML element with contenteditable attribute.

unformattedPaste attribute is experimental because here is used obsolete document.execCommand() method to write unformated text. So far no good alternative for this method has been found.