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

angular-models

v0.1.4

Published

Backbone-style models and collections for Angular!

Downloads

6

Readme

Build Status

Angular Models

Backbone-style models for Angular. If you're like me, one of the things you miss working with Angular is the lack of clearly defined models and collections which you can pass around to various parts of your app, attach custom methods to, call fetch on to refresh data, etc. I didn't find anything to my needs so I built a simple implementation of backbone models.

How to use

Check out the examples directory for a full working implementation with comments

  • Add a script tag for underscore.js (http://underscorejs.org/) and angular-models.js
  • Add 'angular-models' as a dependency of your app or module:
angular.module( 'myApp', ['angular-models']);
  • Inject 'Model' or 'Collection' and extend it just you would a backbone model giving it a 'urlRoot' for the model or 'url' for the collection just as in Backbone. See backbone (http://backbonejs.org) for more info:
.factory('MyModel', function(Model){
  return Model.extend({
	urlRoot: '/api/mymodel'
  });
  • Now make an instance of the model and call .fetch(), .save(), .toJSON() or other methods as with Backbone.
var model = new MyModel({ id: 400 });
model.fetch();
model.set({ name: 'test' });
model.save();
console.log(model.toJSON());

A couple gotchas

  • The model's attributes are stored as model.atts (shorthand for model.attributes) so your template will need to reference model.atts not just model:
$scope.model = model;
now in the template this will not work:
<p>{{model.title}}</p>
but this will:
<p>{{model.atts.title}}</p>
  • similarly a collections models are stored as collection.models so things like ng-repeat must reference the collection.models:
$scope.collection = collection;
now in the template:
<p ng-repeat="model in collection.models">{{model.attributes.title}}</p>

To do:

Want to help? Yes!

  • achieve better parity and consistency with how Backbone methods, arguments, etc.
  • better test coverage
  • remove dependency on underscore by using angular built in methods
  • clean up
  • better docs and instructions