Learn MVC : Using Angular Summer Note

Introduction

This article demonstrates how to use Angular Summer Note in Visual Studio 2017. Following the below steps, you can use Angular summer note in MVC.

  • Create MVC Project
  • Configure Angular Summer Note
  • Work in Angular Summer Note

Create MVC Project

Open Visual Studio 2017.

MVC

Go to New menu > click New & project. Now, it will open "New Project" window.

MVC

You can select ASP.NET Web Application on Framework 4.5. Enter the name of project in “Solution name” textbox, then click OK button.

MVC

One more window should appear. Select MVC Template in this popup & click OK. Now, start cropping image.

Configure Angular Summer Note

You can download the plug-in from -

Open the _Layout.cshtml and must refer the .js file from downloaded folder to this view page

  1. <script src="~/Scripts/jquery-1.10.2.min.js"></script>  
  2.  <script src="~/Scripts/bootstrap.min.js"></script>  
  3.  <script src="~/PlugIn/moment/min/moment-with-locales.min.js"></script>  
  4.  <script src="~/PlugIn/bootstrap/js/tooltip.js"></script>  
  5.  <link href="~/PlugIn/summernote/dist/summernote.css" rel="stylesheet" />  
  6.  <script src="~/PlugIn/summernote/dist/summernote.js"></script>  
  7.  <script src="~/PlugIn/angular/angular.min.js"></script>  
  8.  <script src="~/PlugIn/angular-summernote/dist/angular-summernote.js"></script>  
  9.  <script src="~/PlugIn/angular-ui-router/release/angular-ui-router.js"></script>  

Link your angular configurable file, whatever you given name

  1. <script src="~/App/App.module.js"></script>  
  2. <script src="~/App/App.config.js"></script>  
  3. <script src="~/App/PDFController.js"></script>  

Angular Module

You will need to include the module as a dependency on your application.

  1. var summernote = angular.module('summernote', ['ui.router''summernote']);  

If you have any doubt in configuration, visit the following of my articles

Work in Angular Summer Note

“summernote” is my angular module name .so I have added the “ng-app”

  1. <div class="container body-content" ng-app="summernote">  
  2.         @RenderBody()  
  3. </div>  

Html Code

  1. <div class="panel panel-default" ng-controller="FormInputController" >  
  2.      
  3.         <form method="get" action="/" novalidate="" class="form-horizontal">  
  4.             <fieldset>  
  5.                 <div class="form-group">  
  6.                      
  7.                     <div class="col-sm-12">  
  8.                         <summernote ng-model="htmlContent" height="280"></summernote>  
  9.                         
  10.                         <summernote airmode="" ng-model="htmlContent" class="well reader-block"></summernote>  
  11.                     </div>  
  12.                 </div>  
  13.             </fieldset>  
  14.         </form>  
  15. </div>  

You can use summernote directive where you want to use summer note editor and when the scope is destroyed the directive will be destroyed

If you put markups in the directive, the markups used as initial text.

  1. <summernote><span style="font-weight: bold;">This is initial text.</span></summernote>  

 

Summer note’s options can be specified as attribute

Height

<summernote height="300"></summernote>

Focus

<summernote focus></summernote>

Angular Controller

Initiate the variable

angular

  1.     .module(' summernote ')  
  2.     .controller('FormInputController', FormInputController);  
  3. function FormInputController($scope) {  
  4.       
  5.     $scope.htmlContent = '<h2>Hi</h2><p> Your are in angular summer note session</p>';  
  6.   
  7. }  

Click F5 button and Run the Application. Now it will appear in the browser & see the result.

Output 1

MVC

Summer note is default editing also

Output 2

MVC

If you use the removeMedia button in popover, like below

  1. <summernote airMode config="options" on-media-delete="mediaDelete(target)"></summernote>  

Conclusion

 If you have any queries, please discuss with me via comments section.

Happy Coding!


Similar Articles