我無法激活插入到我網站上的contenteditable區域的Angular指令。如果我使用scope。$ apply(),它表示它已經在運行。Contenteditable Regions中的角度指令
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>
我想它來編譯鏈接並給予href參數的有效鏈接,而是顯示了原始代碼。
JSBin:http://jsbin.com/moponige/1/edit
出於某種原因,只是輸出空的方括號。 [] – James
@詹姆斯請分享代碼。 –