@@ -277,20 +277,20 @@ The following example demonstrates:
277
277
278
278
This example shows how to implement a custom HTML editor widget in Angular.
279
279
280
- <doc:example>
280
+ <doc:example module="formModule" >
281
281
<doc:source>
282
282
<script>
283
283
function EditorCntl($scope) {
284
284
$scope.htmlContent = '<b>Hello</b> <i>World</i>!';
285
285
}
286
286
287
- HTMLEditorWidget.$inject = ['$element ', '$scope ', 'htmlFilter '];
288
- function HTMLEditorWidget(element, scope, htmlFilter ) {
287
+ HTMLEditorWidget.$inject = ['$scope ', '$element ', '$sanitize '];
288
+ function HTMLEditorWidget(scope, element, $sanitize ) {
289
289
scope.$parseModel = function() {
290
290
// need to protect for script injection
291
291
try {
292
- this.$viewValue = htmlFilter (
293
- this.$modelValue || '').get() ;
292
+ this.$viewValue = $sanitize (
293
+ this.$modelValue || '');
294
294
if (this.$error.HTML) {
295
295
// we were invalid, but now we are OK.
296
296
this.$emit('$valid', 'HTML');
@@ -312,32 +312,33 @@ This example shows how to implement a custom HTML editor widget in Angular.
312
312
});
313
313
}
314
314
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
+ };
333
334
</script>
334
335
<form name='editorForm' ng:controller="EditorCntl">
335
336
<div ng:html-editor-model="htmlContent"></div>
336
337
<hr/>
337
338
HTML: <br/>
338
339
<textarea ng:model="htmlContent" cols="80"></textarea>
339
340
<hr/>
340
- <pre>editorForm = {{editorForm}}</pre>
341
+ <pre>editorForm = {{editorForm|json }}</pre>
341
342
</form>
342
343
</doc:source>
343
344
<doc:scenario>
0 commit comments