0

I have a problem to convert string to HTML code. I just want to convert &#160 to HTML code, This value set from variable String. this is my code

ngOnInit(){
    this.submitButtonText = 'Save';
    this.spaceMenu= '   ';
    this.form = this.fb.group({
        'id': [],
        'name': ['', Validators.compose([Validators.required,Validators.minLength(3)])],
        'description': []
    });
    this.name = this.form.controls['name'];
    this.description = this.form.controls['description'];
    this.service.getMenuGroup()
        .subscribe(
            data => this.setMenuGroup(data['menuGroup']),
            err => this.logError(err),
            () => this.finishedGetIndexList('Save')
        );
        this.statusForm = 'Add';
        if(this.id){
            this.fetchData();
        }
    }
<div *ngFor="let item of menuList" [ngClass]="class">
    <label class="checkbox-inline custom-checkbox nowrap">
        <md-checkbox
        [name]="checkboxMenu"
        [checked]="(_checkingList(item,selectedMenu))"
        [indeterminate]="(_checkIsIndeterminate(item,selectedMenu))"
                                            (change)="_onChange(item,$event)"
        [disabled]="true">
        {{item.name}}
        </md-checkbox>
    </label>
</div>

this.spaceMenu, it is a string variable that holds a value &#160. I want to insert it before <md-checkbox.

If anyone could help me ?

Super User
  • 9,448
  • 3
  • 31
  • 47
Rachmat Chang
  • 187
  • 2
  • 7
  • 18

1 Answers1

0
<label ...>
<span [outerHTML]="spaceMenu | safeHtml"></span>
<md-checkbox ...

For details about the safeHtml pipe see In RC.1 some styles can't be added using binding syntax
Not sure whether it is necessary here at all or not.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • function of my code is to make the treeview, TreeView and now I have to do, so I don't use this code again, thanks for the reply. – Rachmat Chang Jan 03 '17 at 04:48