var markdownCompilerModule = angular.module('mdown', []); markdownCompilerModule.factory('Compiler', function(){ return { compile: function(source){ return window.marked(source); } } }); var markdownApp = angular.module("markdownApp", ['ngSanitize', 'mdown']); var markdownController = function($scope, Compiler){ $scope.editor = { source: "", compiled: "" } $scope.compile = function(){ if($scope.editor.source.length != 0){ $scope.editor.compiled = Compiler.compile($scope.editor.source); $scope.rawSource = $scope.editor.compiled; }else{ alert("Whoops. It seems you haven't start typing yet!"); } } $scope.$watch('editor.source', function(source){ if(source){ $scope.editor.compiled = Compiler.compile(source); } }); } // Inject dependencies. Good for minification. markdownController.$inject = ['$scope', 'Compiler']; // Name the controllers for the app. markdownApp.controller("markdownController", markdownController);