#How to
| (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); |