Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A text diff component library for Angular

License

NotificationsYou must be signed in to change notification settings

AXeL-dev/ngx-diff2html

Repository files navigation

NPM versionDownloadsLicenseDonate

A simple text diff component for Angular, based ondiff-match-patch &diff2html.

Demo

ngx-diff2html Demo

Installation

npm install --save ngx-diff2html

Usage

1. Register theNgxDiff2htmlModule in a module, for example app module:

  import { BrowserModule } from '@angular/platform-browser';  import { NgModule } from '@angular/core';  import { AppComponent } from './app.component';+ import { NgxDiff2htmlModule } from 'ngx-diff2html';  @NgModule({    declarations: [AppComponent],    imports: [      BrowserModule,+     NgxDiff2htmlModule    ],    providers: [],    bootstrap: [AppComponent]  })  export class AppModule {}

2. Import diff2html css instyles.css:

  /* You can add global styles to this file, and also import other style files */+ @import "~diff2html/bundles/css/diff2html.min.css";

3. You may also need to add the following lines topolyfills.ts:

  // Add global to window, assigning the value of window itself.+ (window as any).global = window;+ (window as any).process = { env: { DEBUG: undefined } };

4. Start using the component:

<ngx-diff2htmlleft="some text"right="some other text"></ngx-diff2html>

API

  • module:NgxDiff2htmlModule
  • service:NgxDiff2htmlService
  • component:NgxDiff2htmlComponent
  • selector:ngx-diff2html

Inputs

InputTypeRequiredDescription
leftstringYesFirst text to be compared
rightstringYesSecond text to be compared
filenamestringOptional, default: '' (empty)Can be used to display a filename at the top of diff results
formatDiffFormatOptional, default:side-by-sidePossible values:
-side-by-side
-line-by-line
styleDiffStyleOptional, default:wordPossible values:
-word
-char
showContextbooleanOptional, default:falseEnable to show context lines

Outputs

OutputTypeRequiredDescription
diffChangestringOptionalEvent fired when diff changes. Returns text diff inunified format

Methods

NgxDiff2htmlService.getDiff(text1, text2, filename)

Get text diff betweentext1 &text2 inunified format.

Returns:

  • string diff

NgxDiff2htmlService.diffToHTML(diff, format, style)

Convert unified diff string to HTML using diff2html.

Returns:

  • string HTML diff

Example:

import{Component}from'@angular/core';import{NgxDiff2htmlService}from'ngx-diff2html';@Component({selector:'app-root',template:`<div [innerHtml]="diffHTML"></div>`,styles:[],providers:[NgxDiff2htmlService]})exportclassAppComponent{diffHTML:string=null;constructor(privatediffService:NgxDiff2htmlService){constdiff=this.diffService.getDiff('first text','second text');this.diffHTML=this.diffService.diffToHTML(diff);}}

Build

Runng build ngx-diff2html to build the project. The build artifacts will be stored in thedist/ directory.

Publishing

After building your library withng build ngx-diff2html, go to the dist foldercd dist/ngx-diff2html and runnpm publish.

License

This project is licensed under theMIT license.

About

A text diff component library for Angular

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors3

    •  
    •  
    •  

    [8]ページ先頭

    ©2009-2025 Movatter.jp