【发布时间】:2014-03-13 15:38:45
【问题描述】:
我无法激活插入到我网站上内容可编辑区域的 Angular 指令。如果我使用 scope.$apply(),它表示它已经在运行了。
JS
angular.module('app', [])
.directive('edit', function(){
return {
link: function(scope, elm, attr){
scope.url = "http://www.google.com";
scope.press = function(){
document.execCommand('insertHTML', false, '<a ng-href="{{url}}">test</a>');
};
}
};
});
HTML:
<div edit contenteditable="true">Dummy Text</div>
<button ng-click="press()">Press</button>
我希望它编译 url 并在 href 参数中提供有效链接,而不是显示原始代码。
【问题讨论】:
标签: javascript angularjs wysiwyg execcommand