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 🙏

© 2026 – Pkg Stats / Ryan Hefner

extends-ng-model

v1.0.0

Published

This project builds on top of ngModel to add new features to angular

Readme

Extends ngModel   Build Status Image Coverage Status Image

Overview

Based on angular's documentation

The ngModel directive binds an input, select, textarea (or custom form control) to a property on the scope using NgModelController, which is created and exposed by this directive.

This project builds on top of this to add new features for ngModel.

Getting started

  1. Download the library using one of the three terminal commands bellow:
  • $ bower install git://github.com/plippe/extends-ng-model.git --save
  • $ npm install git://github.com/plippe/extends-ng-model.git --save
  • $ git clone [email protected]:Plippe/extends-ng-model.git
  1. Load angular.min.js
  2. Load extends-ng-model.min.js
  3. Add extendsNgModel to your module's dependencies.

Your html should look similar to the following

<!doctype html>
<html ng-app="myApp">
<head>
  ...
</head>
<body>
    ...
    <!-- Load Angular -->
    <script src="bower_components/angular/angular.min.js"></script>
    <!-- Load Extends ngModel -->
    <script src="bower_components/extends-ng-model/dist/extends-ng-model.min.js">
    </script>
    ...
    <script>
        var myApp = angular.module('myApp', [
          ...
          // Add Extends ngModel to your module's dependencies
          'extendsNgModel',
          ...
        ]);
    </script>
    ...
</body>
</html>

Storage

Angular binds input with variables making it easy to access a form's values, but not all values should be limited to a scope or a reduced life time. The following directives synchronize ngModel and angular's built in store to add functionality.

ngModelCache

Having pages broken down into small, reusable, and testable directives is something to aim for, but the scope can make this difficult. ngModelCache synchronize ngModel and angular's $cache. The cache is volatile, but is accessible across multiple scopes.

The following example will save the user's name in the $cache. If the $cache or the input changes, the other will update itself.

<label for="firstName">First Name</label>
<input name="firstName" ng-model="form.firstName" ng-model-cache="" />

A custom cache name can be supplied like in the example bellow.

<label for="firstName">First Name</label>
<input name="firstName" ng-model="form.firstName" ng-model-cache="firstName" />

ngModelCookie

User's don't like inputting the same information multiple times especially if it can be saved over multiple sessions. ngModelCookie synchronize ngModel and angular's $cookies. Cookies are non-volatile making them perfect for short term to medium term options.

The following example will save the page's size in a $cookie. If the $cookie or the input changes, the other will update itself.

<label for="pageSize">Page Size</label>
<input name="pageSize" ng-model="form.pageSize" ng-model-cookie="" />

A custom cookie name can be supplied like in the example bellow.

<label for="pageSize">Page Size</label>
<input name="pageSize" ng-model="form.pageSize" ng-model-cookie="pageSize" />

**Warning:** `ngModelCookie` requires the `ngCookies` module to work


### ngModelLocation

Being able to save or share a URL makes it more likely that the current user and new ones will come visit the application. `ngModelLocation` synchronize `ngModel` and angular's [`$location.search`](https://docs.angularjs.org/api/ng/service/$location). The URL works wonders for searches and filter, as the information isn't private and other links rarely require a form.

The following example will save the search query in the URL. If the URL or the `input` changes, the other will update itself.

```html
<label for="search">Search</label>
<input name="search" ng-model="form.q" ng-model-location="" />

A custom query string name can be supplied like in the example bellow.

<label for="search">Search</label>
<input name="search" ng-model="form.q" ng-model-location="q" />

Custom Storage Read / Write

Directives that read and write to storage have a default converter that provide basic functionality. If you require something more specific feel free to add your own custom converters.

Custom converters are wired up during the configuration phase. There are two lists of converters, one is called when writing from the model to the storage (pushToStorageConverter), while the other does the opposite (pushFromStorageConverter). These take two functions as arguments. The first one takes the element's attribute and should return true if you wish the converter to be applied to this element. The second function takes the value and returns the updated value.

The following example will store ngModelLocation numbers as hexadecimal values in the query string over the default decimal format.

angular
  .module("myApp", ['extendsNgModel'])
  .config(function(ngModelConverterProvider) {
    var isNumber = function(attr) { return attr.type === 'number'; },
      toHex = function(modelValue) { return modelValue.toString(16); },
      fromHex = function(storageValue) { return parseInt(storageValue, 16); };

    ngModelConverterProvider.pushToStorageConverter(isNumber, toHex);
    ngModelConverterProvider.pushFromStorageConverter(isNumber, fromHex);
  });

Warning: Only the first positive converter is applied

For more examples please see the appropriate folder.

Formatters / Parsers

Angular's ngModel has two main pieces, a variable to hold the value, and an input to display and alter it. ngModelController, obtain by requiring ngModel in a directive, offers ways the alter the variable based on the input with $parsers and the input based on the variable with $formatters.

The following use $parsers and $formatters to convert the input data into a more useful type.

ngModelTimestamp

A JavaScript date object is represented as a string when sent to the back end. Converting this string back to a date isn't always straight forward. ngModelTimestamp converts date inputs on the UI to time stamps in the application. Furthermore, it is compatible with the previously explained storage directives.

The following example will make the date of birth accessible as an time stamp and not a date.

<label for="dob">Date of Birth</label>
<input name="dob" type="date"
  ng-model="form.dob"
  ng-model-timestamp="" />

The input can be store in the query string, as a time stamp, like in the example bellow.

<label for="dob">Date of Birth</label>
<input name="dob" type="date"
  ng-model="form.dob"
  ng-model-location=""
  ng-model-timestamp="" />