Libetia A

Libetia A

1576947646

How to Add a Text Editor in Angular 8

The text editor is a program for adding and editing text. In this post, we will learn how to add a text editor in an Angular 8 application.

Prerequisites

  • Basic Knowledge of Angular 2 or higher
  • Visual Studio Code
  • Visual Studio and SQL Server Management studio
  • Node and NPM installed
  • Bootstrap

Step 1

Create an Angular project by using the following command.

ng new TextEditor  

Step 2

Open this project in Visual Studio Code and install bootstrap by using the following command:

npm install bootstrap --save  

Now open styles.css file and add Bootstrap file reference. To add a reference in styles.css file, add this line:

@import '~bootstrap/dist/css/bootstrap.min.css';   

Step 3

Now install ng2-ckeditor library in this project, to install ng2-ckeditor library use the following command:

npm install ng2-ckeditor  

Now add CKEditor javascript reference in index.html file,open Index.html file and the following line:

<script src="https://cdn.ckeditor.com/4.9.2/full-all/ckeditor.js"></script>  

Step 4*

Now include CKEditorModule in app.module.ts file

This is image title

import { BrowserModule } from '@angular/platform-browser';  
import { NgModule } from '@angular/core';  
import { AppRoutingModule } from './app-routing.module';  
import { AppComponent } from './app.component';  
import { CKEditorModule } from 'ng2-ckeditor';  
import { TextEditorComponent } from './text-editor/text-editor.component';  
import { HttpClientModule } from '@angular/common/http';  
import { FormsModule, ReactiveFormsModule } from '@angular/forms';  
import { PagecontentComponent } from './pagecontent/pagecontent.component';  
@NgModule({  
  declarations: [  
    AppComponent,  
    TextEditorComponent,  
    PagecontentComponent  
  ],  
  imports: [  
    BrowserModule,  
    AppRoutingModule,  
    CKEditorModule,  
    HttpClientModule,  
    FormsModule,  
    ReactiveFormsModule  
  
  ],  
  providers: [],  
  bootstrap: [AppComponent]  
})  
export class AppModule { }  

Step 5

Now create a service to call the Web API by using the following command:

ng g s Content  

Now add the following line Content.service.ts file:

import { Injectable } from '@angular/core';  
import { HttpClient } from '@angular/common/http';  
@Injectable({  
  providedIn: 'root'  
})  
export class ContentService {  
  url :any;  
  constructor(private http: HttpClient) { }  
  AddUpdateContent(pagecontent) {  
    debugger  
    this.url = 'http://localhost:56357/Api/Contents/saveconetnt';  
    return this.http.post(this.url, pagecontent);  
}  
Getcontent() {  
  debugger  
  this.url = 'http://localhost:56357/Api/Contents/Getpagdata';  
  return this.http.get(this.url);  
}  
GetcontentById(Id) {  
  debugger  
  this.url = 'http://localhost:56357/Api/Contents/GetpagecontentBy?Id='+Id;  
  return this.http.get(this.url);  
}  
}  

Step 6

Create a class named “Content” by using the following command and add the following lines:

export class Content {  
    Id:number;  
    Title:string;  
    Content:string;  
}  

Step 7

Now let’s create 3 new components by using the following commands:

  1. Texteditor
  2. Pagecontent
  3. detailspost
ng g c Texteditor   
ng g c pagecontent   
ng g c detailspost

Step 8

Now, open texteditor.component.html and add the following HTML code to design the registration form:

<form role="form" #myForm="ngForm" accept-charset="UTF-8" (ngSubmit)="onSubmit()" novalidate style="margin: 30px;">    
    <div class="form-group">    
        <input autofocus autocomplete="none" type="text" name="UserName" placeholder="Enter Title"    
            [(ngModel)]="contentdata.Title" class="form-control" required #PageContentTitle="ngModel"    
            id="PageContentTitle">    
    </div>    
    <ckeditor [(ngModel)]="contentdata.Content" #PageContent="ngModel" name="PageContent" required    
        [config]="ckeConfig" debounce="500">    
    </ckeditor>    
    <div class="form-group mt-4">    
        <div class="row">    
            <div class="col-3 col-md-3 mb-3">    
                <button type="submit" class="btn btn-info">Submit</button>    
            </div>    
        </div>    
    </div>    
</form>    

Open texteditor.componet.ts file and add the following lines:

import { Component, OnInit, ViewChild ,ElementRef} from '@angular/core';    
import { ContentService } from "../content.service";     
import { Content } from "../content";    
import { FormGroup, FormBuilder, Validators, NgForm } from '@angular/forms';    
import { Router } from '@angular/router';    
    
@Component({    
  selector: 'app-text-editor',    
  templateUrl: './text-editor.component.html',    
  styleUrls: ['./text-editor.component.css']    
})    
export class TextEditorComponent implements OnInit {    
  name = 'ng2-ckeditor';    
  ckeConfig: any;    
   mycontent: string;    
  log: string   
  @ViewChild('PageContent') PageContent: any;    
  res: any;    
     
  constructor(private contentservice:ContentService,private router: Router) { }    
  contentdata=new Content();    
    
  ngOnInit() {    
    this.Getcontent()    
    this.ckeConfig = {    
      allowedContent: false,    
      extraPlugins: 'divarea',    
      forcePasteAsPlainText: true    
    };    
  }    
  onSubmit()    
  {    
    debugger;    
    debugger;    
    this.contentservice.AddUpdateContent(this.contentdata).subscribe((data : any) => {    
      debugger;    
      alert("Data saved Successfully");    
      this.router.navigate(['/Post']);    
    
    })    
  }    
  Getcontent()    
  {    
    this.contentservice.Getcontent().subscribe((data:any)=>{    
      this.res=data;    
      console.log(this.res);    
    })    
  }    
}    

Step 9

Now, open pagecontent.component.html and add the following HTML:

<table class="table">    
  <thead>    
    <tr>    
      <th scope="col">#</th>    
      <th scope="col">Title</th>    
      <th scope="col">Content</th>    
       <th scope="col">Details</th>    
    </tr>    
  </thead>    
  <tbody>    
    <tr *ngFor="let data of res">    
      <th scope="row">{{data.Id}}</th>    
      <td>{{data.Title}}</td>    
      <td>{{data.Content}}</td>    
      <td>  <button (click)="GetcontentById(data.Id)" type="submit" class="btn btn-info">Details</button></td>     
    </tr>    
  </tbody>    
</table>    

Open pagecontent.componet.ts file and add the following lines:

import { Component, OnInit } from '@angular/core';  
import { ContentService } from "../content.service";   
import { Router } from '@angular/router';  
@Component({  
  selector: 'app-pagecontent',  
  templateUrl: './pagecontent.component.html',  
  styleUrls: ['./pagecontent.component.css']  
})  
export class PagecontentComponent implements OnInit {  
  res: any;  
  terms: any;  
  cont: any;  
  
  constructor(private contentservice:ContentService,private router: Router) { }  
  
  ngOnInit() {  
   this.Getcontent()  
  }  
  Getcontent()  
  {  
    this.contentservice.Getcontent().subscribe((data:any)=>{  
      this.res=data;  
      this.terms= this.res[1].pageContentTitle;  
      this.cont= this.res[1].Content;  
      console.log(this.res);  
    })  
  }  
  GetcontentById(id:number)  
  {  
    this.router.navigate(['/Details'], { queryParams: { Id: id } });  
  }  
  
}  

Step 10

Now, open detailspost.component.html and add the following HTML:

<div>    
        <div>                   
            <h5 style="color:orange;text-align: center">{{this.Title}}</h5>    
            <hr style="color: blue;">    
              <span>     
              <div style="color:#788594" [innerHTML]="this.content"></div>    
              </span>     
        </div>    
    </div>    

Open detailspost.componet.ts file and add the following lines:

import { Component, OnInit } from '@angular/core';  
import { Router, ActivatedRoute, Params } from '@angular/router';  
import { ContentService } from '../content.service';  
  
@Component({  
  selector: 'app-detailspost',  
  templateUrl: './detailspost.component.html',  
  styleUrls: ['./detailspost.component.css']  
})  
export class DetailspostComponent implements OnInit {  
  res: any;  
  Title: any;  
  content: any;  
  
  constructor( private route: ActivatedRoute,private contentservice:ContentService) { }  
  
  ngOnInit() {  
    let Id = this.route.snapshot.queryParams["Id"]  
   this.GetcontentById(Id);  
  }  
  GetcontentById(Id:string)  
  {  
     this.contentservice.GetcontentById(Id).subscribe((data: any)=>{  
       this.res=data;  
       this.Title=this.res.Title  
       this.content=this.res.Content  
       console.log(this.res);  
    });  
  }  
}  

Step 11

Now, open app-routing.module.ts file and add the following lines to create routing:

import { NgModule } from '@angular/core';  
import { Routes, RouterModule } from '@angular/router';  
import { PagecontentComponent } from './pagecontent/pagecontent.component';  
import { TextEditorComponent } from './text-editor/text-editor.component';  
import { DetailspostComponent } from './detailspost/detailspost.component';  
  
const routes: Routes = [  
  { path: '', component: TextEditorComponent },  
  { path: 'Post', component: PagecontentComponent },  
  { path: 'Details', component: DetailspostComponent }  
  
  
]  
@NgModule({  
  imports: [RouterModule.forRoot(routes)],  
  exports: [RouterModule]  
})  
export class AppRoutingModule { }  

Step 12:

Create a new Web API project

Open Visual Studio and create a new project.

This is image title

Step 13

Change the name to Texteditor.

This is image title

Step 14

Choose the template as Web API.

This is image title

Step 15

Right-click the Models folder from Solution Explorer and go to Add >> New Item >> data.

This is image title

Step 16

Click on the “ADO.NET Entity Data Model” option and click “Add”.

This is image title

Step 17

Select EF Designer from the database and click the “Next” button and Add the connection properties. Select the database name on the next page and click OK.

This is image title

Step 18

Check the “Table” checkbox. The internal options will be selected by default. Now, click on the “Finish” button.

This is image title

Our data model is created now.

Step 19

Right-click on the Models folder and add a class Response. Now, paste the following code in these classes.

public class Response    
   {    
       public string Status { get; set; }    
       public string Message { get; set; }    
   }    

Right-click on the Controllers folder and add a new controller. Name it as “Content controller” and add the following namespace in the Content controller.

using TextEditor.Models;  

Now, add a method to insert and update data into the database.

Step 20

Complete Content controller code

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.Net.Http;  
using System.Web.Http;  
using TextEditor.Models;  
  
namespace TextEditor.Controllers  
{  
    public class ContentsController : ApiController  
    {  
        [HttpPost]  
        public object saveconetnt(Content Con)  
        {  
            try  
            {  
                dbCoreEntities2 db = new dbCoreEntities2();  
                Post Em = new Post();  
                if (Em.Id == 0)  
                {  
                    Em.Content = Con.PageContent;  
                    Em.Title =Con.PageContentTitle ;  
                    db.Posts.Add(Em);  
                    db.SaveChanges();  
                    return new Response  
                    { Status = "Success", Message = "SuccessFully Saved." };  
                }  
            }  
            catch (Exception ex)  
            {  
  
                throw;  
            }  
            return new Response  
            { Status = "Error", Message = "Invalid Data." };  
        }  
       [Route("Api/Contents/Getpagdata")]  
        [HttpGet]  
        public object Getpagecontent()  
        {  
            dbCoreEntities2 db = new dbCoreEntities2();  
            return db.Posts.ToList();  
        }  
        //[Route("Api/Login/")]  
        [HttpGet]  
        public object GetpagecontentById(int id)  
        {  
            dbCoreEntities2 db = new dbCoreEntities2();  
            var obj = db.Posts.Where(x => x.Id == id).ToList().FirstOrDefault();  
            return obj;  
        }  
    }  
  
}    

Step 21

Now, let’s enable CORS. Go to Tools, open NuGet Package Manager, search for CORS, and install the “Microsoft.Asp.Net.WebApi.Cors” package. Open Webapiconfig.cs and add the following lines:

EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");      
config.EnableCors(cors);

Step 22

Now, go to visual studio code and run the project by using the following command: ‘npm start’

This is image title

Enter some values, add styles to text in text editor and click on the submit button.

This is image title

Click on the details button and check.

This is image title

Thank for reading. Did you find this information helpful?

#Angular #Angular 8 #Asp.net #Web API #SQL Server

What is GEEK

Buddha Community

How to Add a Text Editor in Angular 8
Christa  Stehr

Christa Stehr

1598940617

Install Angular - Angular Environment Setup Process

Angular is a TypeScript based framework that works in synchronization with HTML, CSS, and JavaScript. To work with angular, domain knowledge of these 3 is required.

  1. Installing Node.js and npm
  2. Installing Angular CLI
  3. Creating workspace
  4. Deploying your First App

In this article, you will get to know about the Angular Environment setup process. After reading this article, you will be able to install, setup, create, and launch your own application in Angular. So let’s start!!!

Angular environment setup

Install Angular in Easy Steps

For Installing Angular on your Machine, there are 2 prerequisites:

  • Node.js
  • npm Package Manager
Node.js

First you need to have Node.js installed as Angular require current, active LTS or maintenance LTS version of Node.js

Download and Install Node.js version suitable for your machine’s operating system.

Npm Package Manager

Angular, Angular CLI and Angular applications are dependent on npm packages. By installing Node.js, you have automatically installed the npm Package manager which will be the base for installing angular in your system. To check the presence of npm client and Angular version check of npm client, run this command:

  1. npm -v

Installing Angular CLI

  • Open Terminal/Command Prompt
  • To install Angular CLI, run the below command:
  1. npm install -g @angular/cli

installing angular CLI

· After executing the command, Angular CLI will get installed within some time. You can check it using the following command

  1. ng --version

Workspace Creation

Now as your Angular CLI is installed, you need to create a workspace to work upon your application. Methods for it are:

  • Using CLI
  • Using Visual Studio Code
1. Using CLI

To create a workspace:

  • Navigate to the desired directory where you want to create your workspace using cd command in the Terminal/Command prompt
  • Then in the directory write this command on your terminal and provide the name of the app which you want to create. In my case I have mentioned DataFlair:
  1. Ng new YourAppName

create angular workspace

  • After running this command, it will prompt you to select from various options about the CSS and other functionalities.

angular CSS options

  • To leave everything to default, simply press the Enter or the Return key.

angular setup

#angular tutorials #angular cli install #angular environment setup #angular version check #download angular #install angular #install angular cli

Clara  Gutmann

Clara Gutmann

1598716260

Angular 8 CRUD Example | Angular 8 Tutorial For Beginners

Angular 8 CRUD is a basic operation to learn Angular from scratch. We will learn how to build a small web application that inserts, read data, update and delete data from the database. You will learn how to create a MEAN Stack web application. In this Angular 8 Tutorial Example, you will learn a new framework by building a crud application.

New features of Angular 8

You check out the new features in brief on my  Angular 8 New Features post.

I have designed this Angular 8 CRUD Tutorial, especially for newcomers, and it will help you to up and running with the latest version of Angular, which is right now 8.

#angular #angular 8 #angular 8 crud

Libetia A

Libetia A

1576947646

How to Add a Text Editor in Angular 8

The text editor is a program for adding and editing text. In this post, we will learn how to add a text editor in an Angular 8 application.

Prerequisites

  • Basic Knowledge of Angular 2 or higher
  • Visual Studio Code
  • Visual Studio and SQL Server Management studio
  • Node and NPM installed
  • Bootstrap

Step 1

Create an Angular project by using the following command.

ng new TextEditor  

Step 2

Open this project in Visual Studio Code and install bootstrap by using the following command:

npm install bootstrap --save  

Now open styles.css file and add Bootstrap file reference. To add a reference in styles.css file, add this line:

@import '~bootstrap/dist/css/bootstrap.min.css';   

Step 3

Now install ng2-ckeditor library in this project, to install ng2-ckeditor library use the following command:

npm install ng2-ckeditor  

Now add CKEditor javascript reference in index.html file,open Index.html file and the following line:

<script src="https://cdn.ckeditor.com/4.9.2/full-all/ckeditor.js"></script>  

Step 4*

Now include CKEditorModule in app.module.ts file

This is image title

import { BrowserModule } from '@angular/platform-browser';  
import { NgModule } from '@angular/core';  
import { AppRoutingModule } from './app-routing.module';  
import { AppComponent } from './app.component';  
import { CKEditorModule } from 'ng2-ckeditor';  
import { TextEditorComponent } from './text-editor/text-editor.component';  
import { HttpClientModule } from '@angular/common/http';  
import { FormsModule, ReactiveFormsModule } from '@angular/forms';  
import { PagecontentComponent } from './pagecontent/pagecontent.component';  
@NgModule({  
  declarations: [  
    AppComponent,  
    TextEditorComponent,  
    PagecontentComponent  
  ],  
  imports: [  
    BrowserModule,  
    AppRoutingModule,  
    CKEditorModule,  
    HttpClientModule,  
    FormsModule,  
    ReactiveFormsModule  
  
  ],  
  providers: [],  
  bootstrap: [AppComponent]  
})  
export class AppModule { }  

Step 5

Now create a service to call the Web API by using the following command:

ng g s Content  

Now add the following line Content.service.ts file:

import { Injectable } from '@angular/core';  
import { HttpClient } from '@angular/common/http';  
@Injectable({  
  providedIn: 'root'  
})  
export class ContentService {  
  url :any;  
  constructor(private http: HttpClient) { }  
  AddUpdateContent(pagecontent) {  
    debugger  
    this.url = 'http://localhost:56357/Api/Contents/saveconetnt';  
    return this.http.post(this.url, pagecontent);  
}  
Getcontent() {  
  debugger  
  this.url = 'http://localhost:56357/Api/Contents/Getpagdata';  
  return this.http.get(this.url);  
}  
GetcontentById(Id) {  
  debugger  
  this.url = 'http://localhost:56357/Api/Contents/GetpagecontentBy?Id='+Id;  
  return this.http.get(this.url);  
}  
}  

Step 6

Create a class named “Content” by using the following command and add the following lines:

export class Content {  
    Id:number;  
    Title:string;  
    Content:string;  
}  

Step 7

Now let’s create 3 new components by using the following commands:

  1. Texteditor
  2. Pagecontent
  3. detailspost
ng g c Texteditor   
ng g c pagecontent   
ng g c detailspost

Step 8

Now, open texteditor.component.html and add the following HTML code to design the registration form:

<form role="form" #myForm="ngForm" accept-charset="UTF-8" (ngSubmit)="onSubmit()" novalidate style="margin: 30px;">    
    <div class="form-group">    
        <input autofocus autocomplete="none" type="text" name="UserName" placeholder="Enter Title"    
            [(ngModel)]="contentdata.Title" class="form-control" required #PageContentTitle="ngModel"    
            id="PageContentTitle">    
    </div>    
    <ckeditor [(ngModel)]="contentdata.Content" #PageContent="ngModel" name="PageContent" required    
        [config]="ckeConfig" debounce="500">    
    </ckeditor>    
    <div class="form-group mt-4">    
        <div class="row">    
            <div class="col-3 col-md-3 mb-3">    
                <button type="submit" class="btn btn-info">Submit</button>    
            </div>    
        </div>    
    </div>    
</form>    

Open texteditor.componet.ts file and add the following lines:

import { Component, OnInit, ViewChild ,ElementRef} from '@angular/core';    
import { ContentService } from "../content.service";     
import { Content } from "../content";    
import { FormGroup, FormBuilder, Validators, NgForm } from '@angular/forms';    
import { Router } from '@angular/router';    
    
@Component({    
  selector: 'app-text-editor',    
  templateUrl: './text-editor.component.html',    
  styleUrls: ['./text-editor.component.css']    
})    
export class TextEditorComponent implements OnInit {    
  name = 'ng2-ckeditor';    
  ckeConfig: any;    
   mycontent: string;    
  log: string   
  @ViewChild('PageContent') PageContent: any;    
  res: any;    
     
  constructor(private contentservice:ContentService,private router: Router) { }    
  contentdata=new Content();    
    
  ngOnInit() {    
    this.Getcontent()    
    this.ckeConfig = {    
      allowedContent: false,    
      extraPlugins: 'divarea',    
      forcePasteAsPlainText: true    
    };    
  }    
  onSubmit()    
  {    
    debugger;    
    debugger;    
    this.contentservice.AddUpdateContent(this.contentdata).subscribe((data : any) => {    
      debugger;    
      alert("Data saved Successfully");    
      this.router.navigate(['/Post']);    
    
    })    
  }    
  Getcontent()    
  {    
    this.contentservice.Getcontent().subscribe((data:any)=>{    
      this.res=data;    
      console.log(this.res);    
    })    
  }    
}    

Step 9

Now, open pagecontent.component.html and add the following HTML:

<table class="table">    
  <thead>    
    <tr>    
      <th scope="col">#</th>    
      <th scope="col">Title</th>    
      <th scope="col">Content</th>    
       <th scope="col">Details</th>    
    </tr>    
  </thead>    
  <tbody>    
    <tr *ngFor="let data of res">    
      <th scope="row">{{data.Id}}</th>    
      <td>{{data.Title}}</td>    
      <td>{{data.Content}}</td>    
      <td>  <button (click)="GetcontentById(data.Id)" type="submit" class="btn btn-info">Details</button></td>     
    </tr>    
  </tbody>    
</table>    

Open pagecontent.componet.ts file and add the following lines:

import { Component, OnInit } from '@angular/core';  
import { ContentService } from "../content.service";   
import { Router } from '@angular/router';  
@Component({  
  selector: 'app-pagecontent',  
  templateUrl: './pagecontent.component.html',  
  styleUrls: ['./pagecontent.component.css']  
})  
export class PagecontentComponent implements OnInit {  
  res: any;  
  terms: any;  
  cont: any;  
  
  constructor(private contentservice:ContentService,private router: Router) { }  
  
  ngOnInit() {  
   this.Getcontent()  
  }  
  Getcontent()  
  {  
    this.contentservice.Getcontent().subscribe((data:any)=>{  
      this.res=data;  
      this.terms= this.res[1].pageContentTitle;  
      this.cont= this.res[1].Content;  
      console.log(this.res);  
    })  
  }  
  GetcontentById(id:number)  
  {  
    this.router.navigate(['/Details'], { queryParams: { Id: id } });  
  }  
  
}  

Step 10

Now, open detailspost.component.html and add the following HTML:

<div>    
        <div>                   
            <h5 style="color:orange;text-align: center">{{this.Title}}</h5>    
            <hr style="color: blue;">    
              <span>     
              <div style="color:#788594" [innerHTML]="this.content"></div>    
              </span>     
        </div>    
    </div>    

Open detailspost.componet.ts file and add the following lines:

import { Component, OnInit } from '@angular/core';  
import { Router, ActivatedRoute, Params } from '@angular/router';  
import { ContentService } from '../content.service';  
  
@Component({  
  selector: 'app-detailspost',  
  templateUrl: './detailspost.component.html',  
  styleUrls: ['./detailspost.component.css']  
})  
export class DetailspostComponent implements OnInit {  
  res: any;  
  Title: any;  
  content: any;  
  
  constructor( private route: ActivatedRoute,private contentservice:ContentService) { }  
  
  ngOnInit() {  
    let Id = this.route.snapshot.queryParams["Id"]  
   this.GetcontentById(Id);  
  }  
  GetcontentById(Id:string)  
  {  
     this.contentservice.GetcontentById(Id).subscribe((data: any)=>{  
       this.res=data;  
       this.Title=this.res.Title  
       this.content=this.res.Content  
       console.log(this.res);  
    });  
  }  
}  

Step 11

Now, open app-routing.module.ts file and add the following lines to create routing:

import { NgModule } from '@angular/core';  
import { Routes, RouterModule } from '@angular/router';  
import { PagecontentComponent } from './pagecontent/pagecontent.component';  
import { TextEditorComponent } from './text-editor/text-editor.component';  
import { DetailspostComponent } from './detailspost/detailspost.component';  
  
const routes: Routes = [  
  { path: '', component: TextEditorComponent },  
  { path: 'Post', component: PagecontentComponent },  
  { path: 'Details', component: DetailspostComponent }  
  
  
]  
@NgModule({  
  imports: [RouterModule.forRoot(routes)],  
  exports: [RouterModule]  
})  
export class AppRoutingModule { }  

Step 12:

Create a new Web API project

Open Visual Studio and create a new project.

This is image title

Step 13

Change the name to Texteditor.

This is image title

Step 14

Choose the template as Web API.

This is image title

Step 15

Right-click the Models folder from Solution Explorer and go to Add >> New Item >> data.

This is image title

Step 16

Click on the “ADO.NET Entity Data Model” option and click “Add”.

This is image title

Step 17

Select EF Designer from the database and click the “Next” button and Add the connection properties. Select the database name on the next page and click OK.

This is image title

Step 18

Check the “Table” checkbox. The internal options will be selected by default. Now, click on the “Finish” button.

This is image title

Our data model is created now.

Step 19

Right-click on the Models folder and add a class Response. Now, paste the following code in these classes.

public class Response    
   {    
       public string Status { get; set; }    
       public string Message { get; set; }    
   }    

Right-click on the Controllers folder and add a new controller. Name it as “Content controller” and add the following namespace in the Content controller.

using TextEditor.Models;  

Now, add a method to insert and update data into the database.

Step 20

Complete Content controller code

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.Net.Http;  
using System.Web.Http;  
using TextEditor.Models;  
  
namespace TextEditor.Controllers  
{  
    public class ContentsController : ApiController  
    {  
        [HttpPost]  
        public object saveconetnt(Content Con)  
        {  
            try  
            {  
                dbCoreEntities2 db = new dbCoreEntities2();  
                Post Em = new Post();  
                if (Em.Id == 0)  
                {  
                    Em.Content = Con.PageContent;  
                    Em.Title =Con.PageContentTitle ;  
                    db.Posts.Add(Em);  
                    db.SaveChanges();  
                    return new Response  
                    { Status = "Success", Message = "SuccessFully Saved." };  
                }  
            }  
            catch (Exception ex)  
            {  
  
                throw;  
            }  
            return new Response  
            { Status = "Error", Message = "Invalid Data." };  
        }  
       [Route("Api/Contents/Getpagdata")]  
        [HttpGet]  
        public object Getpagecontent()  
        {  
            dbCoreEntities2 db = new dbCoreEntities2();  
            return db.Posts.ToList();  
        }  
        //[Route("Api/Login/")]  
        [HttpGet]  
        public object GetpagecontentById(int id)  
        {  
            dbCoreEntities2 db = new dbCoreEntities2();  
            var obj = db.Posts.Where(x => x.Id == id).ToList().FirstOrDefault();  
            return obj;  
        }  
    }  
  
}    

Step 21

Now, let’s enable CORS. Go to Tools, open NuGet Package Manager, search for CORS, and install the “Microsoft.Asp.Net.WebApi.Cors” package. Open Webapiconfig.cs and add the following lines:

EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");      
config.EnableCors(cors);

Step 22

Now, go to visual studio code and run the project by using the following command: ‘npm start’

This is image title

Enter some values, add styles to text in text editor and click on the submit button.

This is image title

Click on the details button and check.

This is image title

Thank for reading. Did you find this information helpful?

#Angular #Angular 8 #Asp.net #Web API #SQL Server

Clara  Gutmann

Clara Gutmann

1598727360

Angular 8 Updates And Summary of New Features

Angular 8 Updates And Summary of New Features is today’s topic. Angular 8 arrives with an impressive list of changes and improvements including the much-anticipated Ivy compiler as an opt-in feature. You can check out  Angular 7 features and updates if you have not seen yet. In this blog, we have written some articles about  Angular 7 Crud,  Angular 7 Routing,  Angular ngClass,  Angular ngFor.

Angular 8 Updates And Summary

See the following updates.

TypeScript 3.4

Angular 8.0 is now supported TypeScript 3.4, and even requires it, so you will need to upgrade.

You can look at what  TypeScript 3.3 and  TypeScript 3.4 brings on the table on official Microsoft blog.

#angular #typescript #angular 7 crud #angular 7 routing #angular 8

Roberta  Ward

Roberta Ward

1593184320

Basics of Angular: Part-1

What is Angular? What it does? How we implement it in a project? So, here are some basics of angular to let you learn more about angular.

Angular is a Typescript-based open-source front-end web application platform. The Angular Team at Google and a community of individuals and corporations lead it. Angular lets you extend HTML’s syntax to express your apps’ components clearly. The angular resolves challenges while developing a single page and cross-platform applications. So, here the meaning of the single-page applications in angular is that the index.html file serves the app. And, the index.html file links other files to it.

We build angular applications with basic concepts which are NgModules. It provides a compilation context for components. At the beginning of an angular project, the command-line interface provides a built-in component which is the root component. But, NgModule can add a number of additional components. These can be created through a template or loaded from a router. This is what a compilation context about.

What is a Component in Angular?

Components are key features in Angular. It controls a patch of the screen called a view. A couple of components that we create on our own helps to build a whole application. In the end, the root component or the app component holds our entire application. The component has its business logic that it does to support the view inside the class. The class interacts with the view through an API of properties and methods. All the components added by us in the application are not linked to the index.html. But, they link to the app.component.html through the selectors. A component can be a component and not only a typescript class by adding a decorator @Component. Then, for further access, a class can import it. The decorator contains some metadata like selector, template, and style. Here’s an example of how a component decorator looks like:

@Component({
    selector: 'app-root',
    templateUrl: 'app.component.html',
    styleUrls: ['app.component.scss']
})

Role of App Module

Modules are the package of functionalities of our app. It gives Angular the information about which features does my app has and what feature it uses. It is an empty Typescript class, but we transform it by adding a decorator @NgModule. So, we have four properties that we set up on the object pass to @NgModule. The four properties are declarations, imports, providers, and bootstrap. All the built-in new components add up to the declarations array in @NgModule.

@NgModule({
declarations: [
  AppComponent,
],
imports: [
  BrowserModule,
  HttpClientModule,
  AppRoutingModule,
  FormsModule
],
bootstrap: [AppComponent]
})

What is Data Binding?

Data Binding is the communication between the Typescript code of the component and the template. So, we have different kinds of data binding given below:

  • When there is a requirement to output data from our Typescript code in the HTML template. String interpolation handles this purpose like {{data}} in HTML file. Property Binding is also used for this purpose like [property] = “data”.
  • When we want to trigger any event like clicking a button. Event Binding works while we react to user events like (event) = “expression”.
  • When we can react to user events and output something at the same time. Two-way Binding is used like [(ngModel)] = “data”.

image for understanding data binding

#angular #javascript #tech blogs #user interface (ui) #angular #angular fundamentals #angular tutorial #basics of angular