Skip to content

Commit 1940eab

Browse files
committed
use ng-bind-html-unsafe from custom directive (was removed from AngularJS 1.2)
1 parent 944c723 commit 1940eab

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

app/assets/javascripts/directives.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ angular.module('birdwatch.directives', ['charts.barchart', 'charts.wordcloud'])
88
restrict: 'C',
99
scope: { tweet: "=tweet" },
1010
templateUrl: "/assets/templates/tweetCard.tpl.html",
11-
link: function (scope, elem, attrs) { }
11+
link: function (scope, elem, attrs) { console.log(scope) }
1212
}
1313
})
1414
.directive('barchart', function (barchart) {
@@ -87,4 +87,22 @@ angular.module('birdwatch.directives', ['charts.barchart', 'charts.wordcloud'])
8787
});
8888
}
8989
}
90-
});
90+
})
91+
//from http://stackoverflow.com/questions/18340872/how-do-you-use-sce-trustashtmlstring-to-replicate-ng-bind-html-unsafe-in-angu
92+
.directive('ngBindHtmlUnsafe', ['$sce', function($sce){
93+
return {
94+
scope: {
95+
ngBindHtmlUnsafe: '='
96+
},
97+
template: "<div ng-bind-html='trustedHtml'></div>",
98+
link: function($scope, iElm, iAttrs, controller) {
99+
$scope.updateView = function() {
100+
$scope.trustedHtml = $sce.trustAsHtml($scope.ngBindHtmlUnsafe);
101+
}
102+
103+
$scope.$watch('ngBindHtmlUnsafe', function(newVal, oldVal) {
104+
$scope.updateView(newVal);
105+
});
106+
}
107+
};
108+
}]);

0 commit comments

Comments
 (0)