andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.54k stars 305 forks source link

sugarjs inside angularjs scopes #456

Closed sirpy closed 9 years ago

sirpy commented 10 years ago

two quesitons

  1. how can I use sugar js as a standalone function such as underscore. (ie Sugar([1,2,3]).find...)
  2. angularjs uses scopes, so when importing sugarjs only the main windows is extended with sugarjs but angularjs scopes are not. when using angular expressions {{}} sugarjs extended objects are not available
andrewplummer commented 10 years ago
  1. You can't... (yet).
  2. I've tried this out and it works for me. I don't know what you mean by "scopes" but it's possible Angular does do more than a straight "eval" for security purposes, so it's possible that it doesn't work due to this, but I'd have to see it to know more. Maybe you can set up an example?

Otherwise you can simply call a function in your controller/scope/etc. then you should be able to use Sugar as normal.

haydnhkim commented 10 years ago

@sirpy sugarjs extended native javascript object. so, you can uses sugarjs methods inside angular expressions. but, Date and Object are not directly. you have to define methods like $socpe.Date = Date or $scope.Object = Object. then you can uses {{ Date.create() }}.

andrewplummer commented 9 years ago

Going to close this one out now as it seems to be answered. Note that right now v2.0.0 is under development which will allow Underscore-like behavior in accessing through a global, which answers your first question.