2017-01-02 58 views
0

我有一個問題將字符串轉換爲HTML代碼。我只想將&#160轉換爲HTML代碼,該值由變量String設置。這是我的代碼將字符串轉換爲Angular 2中的HTML代碼

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,它是包含一個值&#160一個字符串變量。我想在之前插入它<md-checkbox.

如果有人可以幫我嗎?

回答

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

有關safeHtml管詳見In RC.1 some styles can't be added using binding syntax
不知道是否有必要在這裏全部或者沒有。

+0

我的代碼的功能是使樹視圖,TreeView和現在我必須做的,所以我不再使用這個代碼,謝謝你的回覆。 –