Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <body ng-app='testApp'>
  2. <div ng-controller='testCtrl'>
  3. <test-directive ng-model='dataItems'></test-directive>
  4. </div>
  5. </body>
  6.  
  7. var app = angular.module('testApp', ['ngSanitize']);
  8.  
  9. app.controller('testCtrl', ['$scope', function($scope) {
  10. $scope.dataItems = [
  11. { name: 'Test1', rawHtml: '<input type="button" ng-click="onClick(1);" value="Click 1" />' },
  12. { name: 'Test2', rawHtml: '<input type="button" ng-click="onClick(2);" value="Click 2" />' }
  13. ]
  14. }]);
  15.  
  16. app.directive('testDirective', ['$compile', '$sce', function($compile, $sce) {
  17. return {
  18. restrict: 'E',
  19. scope: {
  20. ngModel: "="
  21. },
  22. template: "<ul><li ng-repeat='item in ngModel'><div ng-bind-html="getHtml(item.rawHtml)">{{item.name}}</div></li></ul>",
  23. controller: function($scope) {
  24. $scope.onClick = function(num) {
  25. console.log(num);
  26. }
  27.  
  28. $scope.getHtml = function(html) {
  29. return $sce.trustAsHtml(html);
  30. }
  31. }
  32. }
  33. }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement