Skip to content

Instantly share code, notes, and snippets.

@JasonStoltz
Created February 24, 2015 15:00
Show Gist options
  • Save JasonStoltz/f0ef0d9255dc5a5e1d83 to your computer and use it in GitHub Desktop.
Save JasonStoltz/f0ef0d9255dc5a5e1d83 to your computer and use it in GitHub Desktop.
Using a view presenter in an ng-repeat
/*
Sometimes, in angular, you'll want to wrap an object with some view presenter logic, but not modify the underlying resource.
If you try something like:
`server in serverRequests(requests.resources)` or `server in requests.resources|map:asServerRequest`, you will fail miserably. You will get some depth recursion errors of some sort. There's a reason for it, but I forget the details. The key is to put your wrapping logic an `ng-init`.
*/
<div ng-repeat="server in requests.resources" ng-init="serverRequest=asServerRequest(server)">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment