Skip to content

Instantly share code, notes, and snippets.

@Micka33
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save Micka33/a8481c4acb4f229df21e to your computer and use it in GitHub Desktop.

Select an option

Save Micka33/a8481c4acb4f229df21e to your computer and use it in GitHub Desktop.
An AngularJS module that load raw json datas from the html on load
(function(window, angular, undefined) {'use strict';
angular.module('loadRawData', [])
.directive('rawData', [function() {
return {
restrict: 'A',
link: function ($scope, $element, $attrs)
{
if ( typeof $attrs.ngBind !== 'undefined')
{
var text = ($attrs.initdata ? $attrs.initdatajson : $element.text());
try{
if ($attrs.type.toLowerCase() == 'json')
$scope[$attrs.ngBind] = angular.fromJson(text);
}catch(e){
console.error(e);
console.info('you sent:', text);
console.info('raw-data was expecting:', $attrs.type);
}
}
}
}
}]);
})(window, window.angular);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment