mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-07 08:57:54 +08:00
docs(ngModelController): use $sce and $sanitize in the contenteditable example.
Closes #7464
This commit is contained in:
@@ -934,7 +934,12 @@ var VALID_CLASS = 'ng-valid',
|
||||
* Note that `contenteditable` is an HTML5 attribute, which tells the browser to let the element
|
||||
* contents be edited in place by the user. This will not work on older browsers.
|
||||
*
|
||||
* <example name="NgModelController" module="customControl">
|
||||
* We are using the {@link ng.service:$sce $sce} service here and include the {@link ngSanitize $sanitize}
|
||||
* module to automatically remove "bad" content like inline event listener (e.g. `<span onclick="...">`).
|
||||
* However, as we are using `$sce` the model can still decide to to provide unsafe content if it marks
|
||||
* that content using the `$sce` service.
|
||||
*
|
||||
* <example name="NgModelController" module="customControl" deps="angular-sanitize.js">
|
||||
<file name="style.css">
|
||||
[contenteditable] {
|
||||
border: 1px solid black;
|
||||
@@ -948,8 +953,8 @@ var VALID_CLASS = 'ng-valid',
|
||||
|
||||
</file>
|
||||
<file name="script.js">
|
||||
angular.module('customControl', []).
|
||||
directive('contenteditable', function() {
|
||||
angular.module('customControl', ['ngSanitize']).
|
||||
directive('contenteditable', ['$sce', function($sce) {
|
||||
return {
|
||||
restrict: 'A', // only activate on element attribute
|
||||
require: '?ngModel', // get a hold of NgModelController
|
||||
@@ -958,7 +963,7 @@ var VALID_CLASS = 'ng-valid',
|
||||
|
||||
// Specify how UI should be updated
|
||||
ngModel.$render = function() {
|
||||
element.html(ngModel.$viewValue || '');
|
||||
element.html($sce.getTrustedHtml(ngModel.$viewValue || ''));
|
||||
};
|
||||
|
||||
// Listen for change events to enable binding
|
||||
@@ -979,7 +984,7 @@ var VALID_CLASS = 'ng-valid',
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}]);
|
||||
</file>
|
||||
<file name="index.html">
|
||||
<form name="myForm">
|
||||
|
||||
Reference in New Issue
Block a user