Skip to content

Commit

Permalink
p3x-ng2-compile-html
Browse files Browse the repository at this point in the history
patrik laszlo
  • Loading branch information
p3x-robot committed Jan 16, 2017
1 parent f827c39 commit eaeb0a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "p3x-ng2-compile-html",
"version": "1.0.33-16",
"version-date": "1/16/2017, 8:28:21 PM",
"version": "1.0.35-18",
"version-date": "1/16/2017, 8:53:13 PM",
"description": "Angular 2 Service to compile an HTML into a component Edit",
"main": "src/index.ts",
"scripts": {
Expand Down
42 changes: 26 additions & 16 deletions test/angular2/app/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,52 @@ import {CompileHtmlService } from '../../../src';
@Component({
selector: 'p3x-ng2-compile-html-text',
template: `
<div #container>loading ...</div>
<div [p3xCompileHtml]="data" [p3xCompileHtmlRef]="ref">loading ...</div>
<div #container></div>
<hr/>
<div [p3xCompileHtml]="data2" [p3xCompileHtmlRef]="ref"></div>
`,
})
@Injectable()
export class Page implements OnInit {

@ViewChild('container', {read: ViewContainerRef}) container: ViewContainerRef;

data: string;
data1: string;
data2: string;

ref: Page;

counter : number = 0;
counter1 : number = 0;
counter2 : number = 0;

constructor( private compileHtmlService: CompileHtmlService ) {
this.ref = this;
this.update();
}

private update() {
this.counter = this.counter + 1;
this.data = `<div>Done</div><a href="javascript:void(0);" (click)="ref.alert('ok')">If click works it says OK!</a>${this.counter}`;
private update1() {
this.counter1++;
this.data1 = `
<div>Service</div><a href="javascript:void(0);" (click)="ref.update1()">Click me via a service!</a>
<div>${this.counter1}</div>
`;
this.compileHtmlService.compile({
template: this.data1,
container: this.container,
ref: this,
})
}

alert(string: string ) {
alert(string);
this.update();
private update2() {
this.counter2++;
this.data2 = `
<div>Attribute</div><a href="javascript:void(0);" (click)="ref.update2()">Click me via a service!</a>
<div>${this.counter2}</div>
`;
}

ngOnInit() {
this.compileHtmlService.compile({
template: this.data,
container: this.container,
ref: this,
})
this.update1();
this.update2();
}

}

0 comments on commit eaeb0a6

Please sign in to comment.