Angular學習-Component中selector的使用

在Angular中,組件裝飾器一般這麼寫:

@Component({    
    selector: 'greet', 
    template: 'Hello {{name}}!'
})

這裏,selector如果是個字符串,那麼其他組件中使用這個組件,需要這麼寫

<greet></greet>

實際上,selector還有其他的寫法,比如說

@Component({    
   selector: '.greet', 
    template: 'Hello {{name}}!'
})

這個時候,你要想使用這個組件,就需要這麼用了:

<div class='greet'></div>

還有,你還可以這麼寫

@Component({    
  selector: ['greet'],
    template: 'Hello {{name}}!'
})

那麼使用這個組件的時候,你還可以這麼調用:

<div greet></div>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章