Skip to content

Instantly share code, notes, and snippets.

@francescoagati
Created July 8, 2012 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save francescoagati/3072621 to your computer and use it in GitHub Desktop.
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
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));
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()
<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