1
如何在元素創建時向元素添加屬性?Angular2將元素添加到元素
我嘗試以下儀表板組件:
import { Component, ElementRef, Renderer } from '@angular/core';
@Component({
selector: '[re-dashboard]',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent {
constructor (private _el: ElementRef, private _renderer: Renderer) {
_renderer.setElementAttribute(_el, 're-component','');
}
}
我想re-component
屬性添加到div正在創建DashboardComponent時。然後,我使用re-component
來創建創建的div。不過,我得到以下錯誤:http://pastebin.com/up35zmUv
任何想法
問候
這是通過添加類。好。不過,我現在更感興趣的方式來做到這一點與代碼並添加一個屬性? – mp3por
編輯 - 這是我想要的。 Sry基因。我已經理解了文檔錯誤 – mp3por
歡迎你!不要忘記選擇答案作爲「接受的答案」來完成這個問題。 – philipooo