Created
July 8, 2012 20:05
-
-
Save francescoagati/3072621 to your computer and use it in GitHub Desktop.
angular.js directive for loading json in view and associate to property scope
This file contains 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
var directives; | |
directives = angular.module("myApp.directives", ['ngResource']); | |
(function(){ | |
this.directive("jsonresource", function($resource){ | |
return function(scope, element, attrs){ | |
console.log(attrs.variable); | |
return scope[attrs.variable] = $resource(attrs.path).get(); | |
}; | |
}); | |
}.call(directives)); |
This file contains 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
directives=angular.module("myApp.directives", ['ngResource']) | |
with directives | |
@directive "jsonresource", ($resource) -> | |
(scope, element, attrs) -> | |
console.log attrs.variable | |
scope[attrs.variable]=$resource(attrs.path).get() | |
This file contains 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
<span jsonresource="" path="prova.json" variable="prova"></span> | |
<span jsonresource="" path="prova.json" variable="prova1"></span> | |
<span jsonresource="" path="prova.json" variable="prova2"></span> | |
{{prova}} | |
{{prova1}} | |
{{prova2}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment