diff --git a/src/angular-markdown-editor.js b/src/angular-markdown-editor.js index 4fff5ea..d3d38a2 100644 --- a/src/angular-markdown-editor.js +++ b/src/angular-markdown-editor.js @@ -11,8 +11,7 @@ angular if (! element.hasClass('processed')) { element.addClass('processed'); - // Setup the markdown WYSIWYG. - element.markdown({ + var markdownOptions = { autofocus: options.autofocus || false, saveable: options.saveable || false, savable: options.savable || false, @@ -63,7 +62,17 @@ angular runScopeFunction(scope, attrs.onShow, e); } } - }); + }; + + // Setup the markdown WYSIWYG. + + // if the markdown editor was added dynamically the markdown function will be undefined + // so it has to be called explicitely + if (element.markdown === undefined){ + element.data('markdown', (data = new $.fn.markdown.Constructor(element[0], markdownOptions))) + } else { + element.markdown(markdownOptions); + } } } };