[英]How to wrap the mention in a special span tag after selecting it? Like Facebook or Stackoverflow tags
我意識到關鍵是
我必須具有以下指令:
.directive('contenteditable', ['$sce', function($sce) { return { restrict: 'A', // only activate on element attribute require: '?ngModel', // get a hold of NgModelController link: function(scope, element, attrs, ngModel) { function read() { var html = element.html(); // When we clear the content editable the browser // leaves a <br> behind // If strip-br attribute is provided then we strip this out if (attrs.stripBr && html === '<br>') { html = ''; } ngModel.$setViewValue(html); } if(!ngModel) return; // do nothing if no ng-model // Specify how UI should be updated ngModel.$render = function() { if (ngModel.$viewValue !== element.html()) { element.html($sce.getTrustedHtml(ngModel.$viewValue || '')); } }; // Listen for change events to enable binding element.on('blur keyup change', function() { scope.$apply(read); }); read(); // initialize } }; }])
我需要將看起來像textarea或輸入文本的div標記為contenteditable
對於我想做的任何奇怪的跨度,我都需要相應地更改此功能
$scope.getPeopleText = function(item) { // note item.label is sent when the typedText wasn't found return '<span class="menu-highlighted">' + (item.name || item.label) + '</span>'; };
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.