Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body ng-app='testApp'>
- <div ng-controller='testCtrl'>
- <test-directive ng-model='dataItems'></test-directive>
- </div>
- </body>
- var app = angular.module('testApp', ['ngSanitize']);
- app.controller('testCtrl', ['$scope', function($scope) {
- $scope.dataItems = [
- { name: 'Test1', rawHtml: '<input type="button" ng-click="onClick(1);" value="Click 1" />' },
- { name: 'Test2', rawHtml: '<input type="button" ng-click="onClick(2);" value="Click 2" />' }
- ]
- }]);
- app.directive('testDirective', ['$compile', '$sce', function($compile, $sce) {
- return {
- restrict: 'E',
- scope: {
- ngModel: "="
- },
- template: "<ul><li ng-repeat='item in ngModel'><div ng-bind-html="getHtml(item.rawHtml)">{{item.name}}</div></li></ul>",
- controller: function($scope) {
- $scope.onClick = function(num) {
- console.log(num);
- }
- $scope.getHtml = function(html) {
- return $sce.trustAsHtml(html);
- }
- }
- }
- }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement