A Text Diff component for Angular.
npm install @miccou/ngx-text-diffcomponent to be used with Angular and based on google diff match patch library.npm i @miccou/ngx-text-diffmodule: NgxTextDiffModule component: NgxTextDiffComponent selector: td-ngx-text-diffDiffContent observable |DiffTableFormat | Optional, default: SideBySide | Possible values:SideBySideLineByLine |false | Possible values:true: shows an loading spinner.false: hides the loading spinner |false | Possible values:true: Only shows lines with differences.false: shows all lines |true | Possible values:true: shows the toolbar.false: hides the format toolbar |true | Possible values:true: shows the format toolbar.false: hides the format toolbar |ngClass object for the outer div |ngStyle object for the outer style |ngClass object for the toolbar div |ngStyle object for the toolbar style |ngClass object for the div surrounding the table rows |ngStyle object for the div surrounding the table rows |true | Possible values:true: Scrolls both tables together.false: Scrolls individually | typescript
export interface DiffContent {
leftContent: string;
rightContent: string;
}export type DiffTableFormat = 'SideBySide' | 'LineByLine';
export interface DiffResults {
hasDiff: boolean;
diffsCount: number;
rowsWithDiff: {
leftLineNumber?: number;
rightLineNumber?: number;
numDiffs: number;
}[];
}
`Usage
1. Register the NgxTextDiffModule in a module, for example app module.
` typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ScrollDispatchModule } from '@angular/cdk/scrolling';import { AppComponent } from './app.component';
import { NgxTextDiffModule } from '@miccou/ngx-text-diff';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, ScrollDispatchModule, NgxTextDiffModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
`` typescript
import { Component, OnInit } from '@angular/core';
import { DiffContent, DiffResults } from '@miccou/ngx-text-diff/lib/ngx-text-diff.model';@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: []
})
export class HomeComponent implements OnInit {
left =
some text to\nbe compared!
right = A changed\n version \n of the text to\nbe compared! constructor() {}
ngOnInit() {
}
onCompareResults(diffResults: DiffResults) {
console.log('diffResults', diffResults);
}
}
`` html
[left]="left"
[right]="right"
(compareResults)="onCompareResults($event)"
>
`Build the NgxTextDiff module
Run
ng build ngx-text-diff to build the library. The build artifacts will be stored in the dist/ngx-text-diff` directory.This project is based on google diff match patch.
Thanks to the original author Alfredo Benassi and most recent maintainer Anargyros Roussos for their work on this project.