floydwch / angular-underscore Goto Github PK
View Code? Open in Web Editor NEWUnderscore adapter for AngularJS
Underscore adapter for AngularJS
Hello,
You are registring the filters in the underscore, the filters and the specific filter (per name) module. This means a filter with the same name is registered 3 times.
Of course you can choose what module you are loading as a dependency of an application.
I just wanted to mention that I think it's not good practice to load a filter with a certain name 3 times. And scripts like stop-angular-overrides are treating this as errors (which is good imho).
Best regards,
Tim
copy-paste of your example:
http://plnkr.co/edit/Rr7WBeiwHbCSeQFZ7l19
I've been using this in my project, but we are using bower
as the package manager. Have you consider to make it installable through bower?
BTW, in order to use this, I also have to include underscore
in my bower.json
file, I want something like angular-underscore
in my json file, thanks!
when i import angular-underscore.js file and inject to angular module, it will have a error like this:
Uncaught ReferenceError: _ is not defined in angular-underscore.js line 157.
have any suggestion?
Can you add an example and describe how to load the module.
Thanks
Could I get an example please?
I am unable to locate licensing details for this project. Can you point me to it or add one?
You could just do:
myApp.filter('_', function(){
return function() {
var args = Array.prototype.slice.call(arguments, 0);
var method = args.splice(1,1)[0];
return _[method].apply(this, args);
}
});
angular.forEach(_, function(method, name){
// prefix all filters with '_' to prevent clobbering (such as $filter('filter') )
myApp..filter('_'+name, function(){
return method;
});
});
Only works for number
type, must be fixed by comparison of alphabet.
Methods which are added in to scope are not defined inside isolated scope. I previously had noticed some weird behaviour in "isSomething" methods, but now I was able to point the issue, when I had "range(1, 11)" used in ng-options. (now I know why "isEmpty" for example is not working in all of my views, reason is isolated scope.)
It worked previously when I wasn't using isolated scope, but when I made changes to the directive it stopped working. Finally I was able to narrow down the issue and made jsfiddle https://jsfiddle.net/RopoMen/sprgjnsm/
My own app is using Angular 1.2 series, but this fiddle is using 1.4.
I really enjoy using Underscore and Angular together, and I was really stoked to use this for filters and whatnot, but could you toss up some more examples of how you're using it?
Can you provide an example for how to use map as a filter?
Hello floydsoft,
thank you for your work, especially the filter stuff works like a charm ;)
What I noticed is that your list of filters must be based on an earlier version (earlier than 1.5.2) of underscore because there are two new methods, introduced in version 1.5.2
Some of the newly introduced methods might possibly make no sense from an template view, but they still can be used as (per definition) filters in controllers using $filter (marked with an ๐บ )
Collections
Array
Utility
How do I load this thing into my controller so I get _
?
I get TypeError: $scope._ is not a function
console.log('_', _); defined
console.log('$window._', $window._); defined
console.log('$scope._',$scope._); undefined
angular-underscore 0.5.0
Awesome. Has anyone packaged this module up as a ruby gem?
When we minify this code in our asset pipeline in rails, it causes an "unknown Provider eProvider" error. It looks like you might be missing the proper array notation to preserve dependency injection when names get mangled. Can you double-check this?
The three functions share the common trait that they use the native setTimeout function.
In angular, it's best practise to use $timeout instead. It offers the same signature, and on top of that it makes it possible to "short circuit time" from karma tests by calling $timeout.flush().
As far as implementation goes, I'm thinking of something along the lines of making the underscoreModule depend upon $timeout and including the three functions from underscore.js as shivs, replacing all instances of 'setTimeout' with '$timeout'.
If you approve of the idea, I could try to make it work and submit a pull request.
Shiv for "min" and "max" breaks "sortedIndex" on arrays of strings:
_.sortedIndex(['a', 'd', 'f'], 'c')
Second argument is transformed to propGetterFactory
:
args[1] = propGetterFactory(args[1]);
https://github.com/floydsoft/angular-underscore/blob/master/angular-underscore.js#L28
Error: 10 $digest() iterations reached. Aborting!
i get this when using groupBy as a filter on a small set of data (20-30 items)
<div id="container">
<div class="item span4 well" ng-repeat="(place_type, places) in groupBy(model.places,'type')">
<a href="#/discover/{{model.id}}/{{place_type}}"><h4>{{place_type}}</h4></a>
</div>
</div>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.