在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>