Hi Sander, I created a directive that added a prefix to contenteditable element and it worked well. I would like to ask you if it is an angular way.
Regards http://plnkr.co/edit/szJeUML7oPrETcumgDHA?p=preview <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>contentEditable add prefix</title> <style type="text/css"> div[contentEditable] { cursor: pointer; background-color: #D0D0D0; } </style> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.1/angular.min.js"></script> </head> <body ng-app="form-example2"> <div contentEditable="true" ng-model="content" title="Click to edit"></div> <script> console.clear(); (function(angular) { 'use strict'; angular.module('form-example2', []).directive('contenteditable', function() { return { require: 'ngModel', link: function(scope, elm, attrs, ctrl) { // view -> model elm.on('input', function() { scope.$apply(function() { ctrl.$setViewValue(elm.html()); }); }); elm.on('blur', function() { scope.$apply(function() { if (ctrl.$viewValue.indexOf('✔ ') == -1) elm.html('✔ ' + ctrl.$viewValue); }); }); elm.on('mouseover', function() { scope.$apply(function() { if (ctrl.$viewValue) elm.html(ctrl.$viewValue.replace('✔ ', '')); }); }); } }; }); })(window.angular); </script> </body> </html> W dniu czwartek, 26 lutego 2015 05:52:29 UTC+1 użytkownik Sander Elias napisał: > > Hi Trzczy, > > A watch does run on every digest cycle. However, you are watching an > element, and that's not where this is intended for. Then you are > manipulating the value of the element. That is not the way you manipulate > data in angular. You really should read through the ngModel > <https://docs.angularjs.org/api/ng/directive/ngModel> documentation. If > you want to do something like this, you can use the ngModelController > <https://docs.angularjs.org/api/ng/type/ngModel.NgModelController>to add > a $formatter/$parser or whatever you see fit. > > If after reading trough these you need some additional help, update your > plunk, and come back to us, and one of us will surely help! > > Regards > Sander > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
