Better angular js validation messages using jquery validator

Angularjs validation messages requires you to

  1. Add lot of html markup
  2. Add validation rules to your html markup.

For simple, short forms this might be good but for big forms and regular use it will not fit. It makes html markup complex, making it hard for user to understand the form validation rules, change messages.

Before angularjs, in the time of jQuery plugins world, there was a plugin (and still exists) used for validations called jQuery Validator. This plugin allows you to keep rules, messages in single javascript object which is very easy to maintain. It also provides good range of validation rules along with custom rule creation.

This jQuery validator plugin can be used in angular js(the angular way), here it is Angular jQuery Validator.

Please see the documentation for how to get started.

It makes validation task really easy and manageable.


Cancel earlier http requests in angularjs

When we want data from last http request, data from earlier request (if any) need to be canceled.

// Code goes here

var canceller = $q.defer();
if(earlierRequest && earlierRequest.canceller)
  // Cancel earlier requests
var earlierRequest = $http({
  // Data received
earlierRequest.canceller = canceller;