Skip to content

Kroid/angular-query-master

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-query-master

Stringify and parse search query strings with nested params. Based on https://github.com/hapijs/qs nodejs package.

Motivation

$location and $routeParams not enought for deep parse query arguments:

// url: /page?users[0][id]=1&users[0][name]=Joe&users[1][id]=2&users[1][name]=Kevin

$location.search()

{
  "users[0][id]": "1",
  "users[0][name]": "Joe",
  "users[1][id]": "2",
  "users[1][name]": "Kevin"
}

Solution

searchParse('users[0][id]=1&users[0][name]=Joe&users[1][id]=2&users[1][name]=Kevin')

{
  users: [
    {id: '1', name: 'Joe'},
    {id: '2', name: 'Kevin'}
  ]
}

Getting started:

Get the code:

Install via Bower $ bower install --save angular-query-master.

Or download the release (minified)

Add module to your application.

index.html:

<html ng-app="app">
  <head></head>
  <body ng-controller="AppController">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js"></script>
    <script src="angular-query-master.min.js"></script>
    <script src="app.js"></script>
  </body>
</html>

app.js

(function() {
  angular
    .module('app', ['queryMaster'])
    .controller('AppController', controller);

  controller.$inject = ['searchParse']

  function controller(searchParse) {
    var parsed = searchParse(location.search.slice(1));
    console.log(parsed);
  }
})();

Documentation

coming soon

About

Angular module for deep parsing query uri

Resources

Stars

Watchers

Forks

Packages

No packages published