Created
July 3, 2013 01:25
-
-
Save edinella/5914748 to your computer and use it in GitHub Desktop.
Obtém dados remotos para o escopo local
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* <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