亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

angular2里的directive理解?

angular2里的directive理解?

千萬里不及你 2019-02-06 20:07:43
export class AppComponent {}我也export了HeroComponent模塊,然后在app.component一開始就import進來,然后在directive加入這些模塊。然后template才能識別相應的selector???不是很明白這句話,我引入的是HeroComponent里的類嗎。然后directive之后,我能怎么用?是繼承他的類嗎
查看完整描述

2 回答

?
慕桂英3389331

TA貢獻2036條經驗 獲得超8個贊

import HeroComponent...
@Component({

........

directive:[HeroComponent]
})
class AppComponent{}


查看完整回答
反對 回復 2019-03-17
?
Helenr

TA貢獻1780條經驗 獲得超4個贊

import只有一個作用,就是把類,變量或者其他東西引入進來,import本身只保證當類需要的時候,存在,可用。

directives的作用就是告訴模版渲染引擎某個標簽有特殊意義,當前template渲染的時候,如果識別到directive內指定的標簽就自動調用相應的組件,填充這個標簽。

import {HeroComponent} from ...

@Component({

  template: `

  <element>...</element>

  <element>...</element>

  ...

  <hero-component>...</hero-component>

  `

  directives: [HeroComponent]

})


@Component({

  selector: "hero-compoennt"

})

export class HeroComponent {

  

}


查看完整回答
反對 回復 2019-03-17
  • 2 回答
  • 0 關注
  • 558 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號