@@ -1466,7 +1466,12 @@ var VALID_CLASS = 'ng-valid',
1466
1466
* Note that `contenteditable` is an HTML5 attribute, which tells the browser to let the element
1467
1467
* contents be edited in place by the user. This will not work on older browsers.
1468
1468
*
1469
- * <example name="NgModelController" module="customControl">
1469
+ * We are using the {@link ng.service:$sce $sce} service here and include the {@link ngSanitize $sanitize}
1470
+ * module to automatically remove "bad" content like inline event listener (e.g. `<span onclick="...">`).
1471
+ * However, as we are using `$sce` the model can still decide to to provide unsafe content if it marks
1472
+ * that content using the `$sce` service.
1473
+ *
1474
+ * <example name="NgModelController" module="customControl" deps="angular-sanitize.js">
1470
1475
<file name="style.css">
1471
1476
[contenteditable] {
1472
1477
border: 1px solid black;
@@ -1480,8 +1485,8 @@ var VALID_CLASS = 'ng-valid',
1480
1485
1481
1486
</file>
1482
1487
<file name="script.js">
1483
- angular.module('customControl', []).
1484
- directive('contenteditable', function() {
1488
+ angular.module('customControl', ['ngSanitize' ]).
1489
+ directive('contenteditable', ['$sce', function($sce ) {
1485
1490
return {
1486
1491
restrict: 'A', // only activate on element attribute
1487
1492
require: '?ngModel', // get a hold of NgModelController
@@ -1490,7 +1495,7 @@ var VALID_CLASS = 'ng-valid',
1490
1495
1491
1496
// Specify how UI should be updated
1492
1497
ngModel.$render = function() {
1493
- element.html(ngModel.$viewValue || '');
1498
+ element.html($sce.getTrustedHtml( ngModel.$viewValue || '') );
1494
1499
};
1495
1500
1496
1501
// Listen for change events to enable binding
@@ -1511,7 +1516,7 @@ var VALID_CLASS = 'ng-valid',
1511
1516
}
1512
1517
}
1513
1518
};
1514
- });
1519
+ }] );
1515
1520
</file>
1516
1521
<file name="index.html">
1517
1522
<form name="myForm">
0 commit comments