【发布时间】:2018-04-12 09:06:31
【问题描述】:
我有一个应用程序,我想在其中创建一个编辑区域,就像 StackOverflow 上的这个一样。我不想使用 textAngular 指令,因为它太难理解了,所以我找到了这个 Javascript 函数 document.execCommand,它似乎正是我所需要的。
问题是我不能让它在 AngularJs 中工作。它没有给出任何错误,它什么也没做。
我有一个内容可编辑的 div:
<div contenteditable id="text"><h5>Select a part of this text!</h5></div>
一个粗体按钮:
<i class="fa fa-bold" ng-click="wrapBold()"></i>
和功能:
$scope.wrapBold = function() {
document.execCommand('bold', false, null);
};
我已经尝试使用$document,我将它注入控制器,但它给了我一个错误提示
TypeError: undefined is not a function at Scope.$scope.wrapBold
【问题讨论】:
-
但似乎
document.execCommand是仅Mozilla 的API -
意味着它不适用于 Angular?
-
你有这方面的 plunker/fiddle 吗?
-
@Adel 谁知道呢,但如果你发现 更容易 使用 Firefox 可用的 API 而不是其他主流浏览器..
标签: javascript angularjs document