第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

@ViewChild和@ContentChild有什么區(qū)別?

@ViewChild和@ContentChild有什么區(qū)別?

互換的青春 2019-11-22 15:06:46
角2提供@ViewChild,@ViewChildren,@ContentChild和@ContentChildren用于查詢一個(gè)組件的派生元素裝飾器。前兩個(gè)和后兩個(gè)有什么區(qū)別?
查看完整描述

3 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

我將使用Shadow DOM和Light DOM術(shù)語(yǔ)回答您的問(wèn)題(它來(lái)自Web組件,請(qǐng)參見(jiàn)此處)。一般來(lái)說(shuō):


影子DOM-是組件的內(nèi)部DOM,由您定義(作為組件的創(chuàng)建者)并向最終用戶隱藏。例如:

@Component({

  selector: 'some-component',

  template: `

    <h1>I am Shadow DOM!</h1>

    <h2>Nice to meet you :)</h2>

    <ng-content></ng-content>

  `;

})

class SomeComponent { /* ... */ }

輕型DOM-是組件的最終用戶提供給組件的DOM。例如:

@Component({

  selector: 'another-component',

  directives: [SomeComponent],

  template: `

    <some-component>

      <h1>Hi! I am Light DOM!</h1>

      <h2>So happy to see you!</h2>

    </some-component>

  `

})

class AnotherComponent { /* ... */ }

因此,您的問(wèn)題的答案非常簡(jiǎn)單:


@ViewChildren和之間的區(qū)別@ContentChildren是,@ViewChildren在Shadow DOM 中查找元素,而@ContentChildren在Light DOM 中查找元素。


查看完整回答
反對(duì) 回復(fù) 2019-11-22
?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊

正如其名,@ContentChild@ContentChildren查詢將返回現(xiàn)有的內(nèi)部指令<ng-content></ng-content>視圖的元素,而@ViewChild@ViewChildren不僅要看直接對(duì)你的視圖模板元素。


查看完整回答
反對(duì) 回復(fù) 2019-11-22
  • 3 回答
  • 0 關(guān)注
  • 1061 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)