angularjs - Appending ngBindHtml function using .attr in link function not working -
a attempting attach ngbindhtml directive in application within link function of directive. module in directive located injects ngsanitize such:
angular.module('ui.bootstrap.contextmenu', ['ngsanitize']) .directive('contextmenu', cm); where cm directive function. link function looks like:
var link = function ($scope, element, attrs) { element.on('contextmenu', function (event) { event.stoppropagation(); $scope.$apply(function () { event.preventdefault(); var options = $scope.$eval(attrs.contextmenu); var model = $scope.$eval(attrs.model); if (options instanceof array) { if (options.length === 0) { return; } rendercontextmenu($scope, event, options, model); } else { throw '"' + attrs.contextmenu + '" not array'; } }); }); }; where rendercontextmenu sketches out html attached body of page. within function have following lines of code:
$div.attr('ng-bind-html', text); $a.append($div); which should produce looks like:
<a><div ng-bind-html="the text"></div></a> and does. problem text not displayed. have thoughts on this?
i think "angular-y" way of doing put html code context menu you're hoping bind directly template, , hide/show appropriate: show if valid contextmenu event occurs , has options.length > 0.
Comments
Post a Comment