@@ -277,20 +277,20 @@ The following example demonstrates:
277277
278278This example shows how to implement a custom HTML editor widget in Angular.
279279
280- <doc:example>
280+ <doc:example module="formModule" >
281281 <doc:source>
282282 <script>
283283 function EditorCntl($scope) {
284284 $scope.htmlContent = '<b>Hello</b> <i>World</i>!';
285285 }
286286
287- HTMLEditorWidget.$inject = ['$element ', '$scope ', 'htmlFilter '];
288- function HTMLEditorWidget(element, scope, htmlFilter ) {
287+ HTMLEditorWidget.$inject = ['$scope ', '$element ', '$sanitize '];
288+ function HTMLEditorWidget(scope, element, $sanitize ) {
289289 scope.$parseModel = function() {
290290 // need to protect for script injection
291291 try {
292- this.$viewValue = htmlFilter (
293- this.$modelValue || '').get() ;
292+ this.$viewValue = $sanitize (
293+ this.$modelValue || '');
294294 if (this.$error.HTML) {
295295 // we were invalid, but now we are OK.
296296 this.$emit('$valid', 'HTML');
@@ -312,32 +312,33 @@ This example shows how to implement a custom HTML editor widget in Angular.
312312 });
313313 }
314314
315- angular.directive('ng:html-editor-model', function() {
316- return ['$formFactory', '$element', function ($formFactory, element) {
317- var exp = element.attr('ng:html-editor-model'),
318- form = $formFactory.forElement(element),
319- widget;
320- element.attr('contentEditable', true);
321- widget = form.$createWidget({
322- scope: this,
323- model: exp,
324- controller: HTMLEditorWidget,
325- controllerArgs: {$element: element}});
326- // if the element is destroyed, then we need to
327- // notify the form.
328- element.bind('$destroy', function() {
329- widget.$destroy();
330- });
331- }];
332- });
315+ angular.module.formModule = function($compileProvider){
316+ $compileProvider.directive('ngHtmlEditorModel', function ($formFactory) {
317+ return function(scope, element, attr) {
318+ var form = $formFactory.forElement(element),
319+ widget;
320+ element.attr('contentEditable', true);
321+ widget = form.$createWidget({
322+ scope: scope,
323+ model: attr.ngHtmlEditorModel,
324+ controller: HTMLEditorWidget,
325+ controllerArgs: {$element: element}});
326+ // if the element is destroyed, then we need to
327+ // notify the form.
328+ element.bind('$destroy', function() {
329+ widget.$destroy();
330+ });
331+ };
332+ });
333+ };
333334 </script>
334335 <form name='editorForm' ng:controller="EditorCntl">
335336 <div ng:html-editor-model="htmlContent"></div>
336337 <hr/>
337338 HTML: <br/>
338339 <textarea ng:model="htmlContent" cols="80"></textarea>
339340 <hr/>
340- <pre>editorForm = {{editorForm}}</pre>
341+ <pre>editorForm = {{editorForm|json }}</pre>
341342 </form>
342343 </doc:source>
343344 <doc:scenario>
0 commit comments