Skip to content

Instantly share code, notes, and snippets.

@edinella
Created July 3, 2013 01:25
Show Gist options
  • Save edinella/5914748 to your computer and use it in GitHub Desktop.
Save edinella/5914748 to your computer and use it in GitHub Desktop.
Obtém dados remotos para o escopo local
/*
* <select get-remote="http://path/to/users.json as users">
* <option ng-repeat="user in users" ng-value="user.id">{{user.name}}</option>
* </select>
*/
.directive('getRemote', function ($http) {
return {
restrict: 'A',
link: function ($scope, $element, $attrs) {
var pars = $attrs.getRemote.toLowerCase().split(' as ');
$http.get(pars[0]).success(function (data) {
$scope[pars[1]] = data;
});
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment