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 🙏

© 2025 – Pkg Stats / Ryan Hefner

angular-editable-text

v2.0.12

Published

angular-editable-text ===================

Downloads

41

Readme

angular-editable-text

Overview

Angular-editable-text is a directive that lets you turn your title or text into an editable, good looking component that will match the style of what your text looks like. It supports 2-way-data-binding, of course, and methods for validating and saving the text after changing, also via promises. An input that inherits the text's style is created - no content editable usage, to theoretically there is support for older browsers.

Demo

Here

Why I created this

Before creating this, I researched other libraries that seem to be fit for the job, but found that they are either too simple for my use cases, or simply do not look good, and do not keep true to your styling (for example, add an input instead of letting you edit your own content).

Installation:

  1. install using npm (or by getting the min.js and min.css files from dist library)
    $ npm install angular-editable-text
  2. include angular-editable-text.min.js & angular.editable-text.min.css in your project
  3. include the module as a dependency of your app.
    angular.module('myApp', ['gg.editableText'])
  4. you are ready to use angular-editable-text!

Usage

Basic:

To allow a line of text, for example, a title of your article editor, to be edited, simply add the "editable-text" attribute set to the relevant property on your model:

HTML:

<h1 gg-editable-text="myTitle"></h1>

Inside yourController.js:

$scope.myTitle='My Initial Title';

This will make your title editable on click. Note that whatever was inside your HTML tag will be transcluded and won't be affected by the dynamic editing part.

Placeholder:

<h1 gg-editable-text="myText" placeholder="your placeholder text">

Also, a "is-placeholder" class will be added so you can style it your own way (#2)

Credit goes to @mmaday!

Select All:

To automatically select all text when entering edit mode, add the "gg-select-all" attribute to the element.

<h1 gg-editable-text="myText" gg-select-all>

Keep Focus on Enter:

By default, hitting Enter/Return will call the on-change handler and blur the input field. To keep focus on the input field after enter, add the 'gg-keep-focus' attribute to the element.

<h1 gg-editable-text="myText" gg-keep-focus>

This only changes the behavior when hitting Enter.

Validating processing, and server requests

To validate content or perform a custom action, process it or send it to your server, you can pass a function as the gg-on-change attribute, with value as its parameter.

If the gg-on-change handler returns undefined, the model will not be updated. This can be useful for binding to a readonly property. The change handler can perform the actions to cause the readonly property to be updated, for example, using a flux store as the model and calling a flux action in the change handler.

Validation and processing example: HTML:

<h1 gg-editable-text="myTitle" gg-on-change="validate(value)"></h1>

yourController.js:

$scope.validate=function validateContent(value){
  var deferred = $q.defer();
  if (value.indexOf('red pinguins')==-1) {
    alert('Title must contain red pinguins!');
    deferred.reject();
  } else {
    deferred.resolve();
  }
  return deferred.promise;
}

Async request example: The on-change function can also return a promise. If the gg-on-change handler returns a promise, the resolved value will be used to update the model. If the promise is rejected, the model is reverted to its original value. If the resolved value is undefined, then the model is not updated (see above).

HTML:

<h1 gg-editable-text="myTitle" gg-on-change="saveToServer(value)"></h1>

yourController.js:

$scope.saveToServer=function saveContent(value){
  var dfd = $q.defer();
$timeout(function () {
              var isOurServerAlive=(Math.random()<0 .7) //simulate an unstable server :);
              if (isOurServerAlive) dfd.resolve(value);
              else dfd.reject(); //rejecting the promise will cancel any changes
            },1500);

	return d.promise;
}

While the promise is being resolved, the default behavior is to display an empty string. In the configuration section you can learn how to change it.

Edit mode control

Sometimes you will need to manually invoke edit mode for a specific component, or to know when a component is being edited. For this purpose, you can bind the attribute "edit-mode" to a property in your model that will be bound 2-ways to the edit mode of a text item.

HTML:

<h2 gg-editable-text="myTitle" gg-edit-mode="isEditing"></h2>

<span ng-show="isEditing">The above h2 tag is being edited right now!</span> <!-- this will show only when the above component is in edit mode -->
<label for="editControl">
<input ng-model="isEditing" type="checkbox" id="editControl">
Toggle editing
</label>

yourController.js:

$scope.myTitle="My Title";
$scope.$watch('isEditing',function(isEditing){
if (isEditing) console.log('My title is being edited!');
});

Configuration

To use a different template when a promise is waiting to be resolved, you can inject EditableTextHelperProvider to a config block as following (here I'm using a FontAwesome spinner instead):

  .module('editableTextDemo', ['gg.editableText'])
    .config(function (EditableTextHelperProvider) {
      EditableTextHelperProvider.setWorkingText('<span class="fa fa-spin fa-spinner"></span>');
    });