Giter VIP home page Giter VIP logo

angular-lodash's Introduction

An AngularJS module adapting lodash

A fork of angular-underscore

This module exposes lodash's API into angular app's root scope, and provides some filters from lodash.

How to use

Install

After loading angular.js and lodash.js:

<script type="text/javascript" src="angular-lodash.js"></script>

Load angular-lodash

Load the whole library

angular.module('app', ['angular-lodash']);

Usecase

uniq

<script type="text/javascript">
  angular.module('example', ['angular-lodash']);
  app.controller('MainCtrl', function($scope) {});
</script>

<body ng-app="example">
  <div ng-controller="MainCtrl">
    <!-- output unique numbers from input.. [1, 2, 3, 4, 5, 6, 7, 8] -->
    <div ng-repeat="num in [1,1,2,3,4,5,5,6,6,7,7,7,8]|uniq">{{num}}</div>
  </div>
</body>

pluck

<script type="text/javascript">
  angular.module('example', ['angular-lodash']);
  app.controller('MainCtrl', function($scope) {
      $scope.exarr = [
        { 'name': 'John', 'age': 26 },
        { 'name': 'Bob', 'age': 41 },
        { 'name': 'Tom', 'age': 32 },
        { 'name': 'Ralph', 'age': 17 },
        { 'name': 'Molly', 'age': 13 }
      ];
  });
</script>

<body ng-app="example">
  <div ng-controller="MainCtrl">
    <div ng-repeat="age in exarr|pluck:'age'">{{age}}</div>
  </div>
</body>

keys

<script type="text/javascript">
  angular.module('example', ['angular-lodash']);
  app.controller('MainCtrl', function($scope) {                                                                                                                                                        
    $scope.exobj = {
      'key1': {
        'subkey1': 1
      },
      'key2': {
        'subkey2': 2
      },
      'key3': {
        'subkey3': 3,
        'subkey31': 31
      }
    };
  }); 
</script>

<body ng-app="example">
  <div ng-controller="MainCtrl">
    <div ng-repeat="k in exobj|keys">{{k}}</div>
  </div>
</body>

angular-lodash's People

Contributors

cabrel avatar dariusk avatar floydwch avatar gautema avatar tero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

angular-lodash's Issues

_.filter doesn't behave as it should with object

Hi,

Due to the fact _.filter proxies to angular's built in filter, using _.filter on an object doesn't work correctly.

I expect the second parameter to be the object key, but instead the object is converted to an array and the second param is the index.

More use cases

More use case would be useful.
Like for every defined filter at least one example.

_ is not defined and browseriy

Hi,

I am getting the dreadful _ is not defined in the file generated by browserify, even though I require the proper libs in the right sequence in the source js file, like such:

require('../../bower_components/angular/angular.js');
require('../../bower_components/lodash/dist/lodash.compat.js');
require('../../bower_components/angular-lodash/angular-lodash.js');

Any thoughts?
Thanks!

join strings

join with empty string as default would be usefull because lodash will convert string into arrays

Make it a variant

Hi Cabrel,

Thanks for the effort in putting library to make it easy to use in Angular.

Lodash is continuously improving, we upgrade when required.

This library should be a variant to lodash. It should be able to provide reference to user installed lodash not to the version this has copied.

I just wanted to state my opinion. Hope you will understand.
Kind regards,
Phani.

lodash as DI service

Hi,

It would be nice if you could also add '' service as well. Even though lodash functions are available in $scope it would be nicer to have '' service in this module as well. Currently I need make that service to all projects, becasue I don't want to write $scope everytime I use lodash inside controller AND I don't want to use global '_' neither.

if('_'.length < '$scope'.length) console.log('This would be nicer to use inside controller :)');

Adding service:

.factory('_', ['$window', function($window) {
  return $window._;
}]);

and jsfiddle from that http://jsfiddle.net/RopoMen/c2sgLjou/

Br,
Markku Roponen

Cannot install with Bower

Hi, I was trying to install via bower but I'm receiving the next error message:

$ bower i --save angular-lodash
bower angular-lodash#*          cached git://github.com/cabrel/angular-lodash.git#0.1.2
bower angular-lodash#*        validate 0.1.2 against git://github.com/cabrel/angular-lodash.git#*
bower lodash#~2.4.1             cached git://github.com/lodash/lodash.git#2.4.2
bower lodash#~2.4.1           validate 2.4.2 against git://github.com/lodash/lodash.git#~2.4.1
bower lodash#>=1.3.0            cached git://github.com/lodash/lodash.git#3.10.1
bower lodash#>=1.3.0          validate 3.10.1 against git://github.com/lodash/lodash.git#>=1.3.0
bower                        ECONFLICT Unable to find suitable version for lodash

But this is my bower.json:

"dependencies": {
    "angular": "~1.4.8",   
    "lodash": "~3.10.1" 
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.