is a simple markup syntax through which it can make normal text content have a certain
angular.module('App', []).directive('markdown', //declare the command and name it markdown function(){ //Create showdown converter var converter = new Showdown.converter(); //The command will return an object to declare the settings of the command return{ //declare the custom action to wait for the value to be assigned to the markdown property scope:{markdown: '@'}, //Declare the link function, its role is 'Convent Markdown To HTML!' link:function(scope,element,attrs){ //The following will use the scope observation period to synchronize model changes scope.$watch('markdown',function(){ var content = converter.makeHtml(attrs.markdown);//Convert markdown to html and assign content variable element.html(content); //Here is to inject the converted result into the element }) } } } );
Then you can use it in the corresponding position that needs to be converted!
<div markdown="{{content.content}}"></div>
Note that your data format must be markdown! otherwise invalid