Dab tsi yog kev txhaj tshuaj nyob rau hauv angular 2 nrog piv txwv?
Dab tsi yog kev txhaj tshuaj nyob rau hauv angular 2 nrog piv txwv?

Video: Dab tsi yog kev txhaj tshuaj nyob rau hauv angular 2 nrog piv txwv?

Video: Dab tsi yog kev txhaj tshuaj nyob rau hauv angular 2 nrog piv txwv?
Video: Ntujtawg yog dab tsi ? 2024, Kaum ib hlis
Anonim

Dependency Txhaj rau hauv Angular 2 muaj peb yam. Cov khoom injector yog siv los tsim ib qho piv txwv ntawm a kev vam khom . Lub injector yog ib tug mechanism uas muab ib txoj kev siv uas a kev vam khom yog instantiated. Tsim ib tug kev vam khom , ib tug injector nrhiav ib tug muab kev pab.

Dhau li ntawm no, dab tsi yog qhov kev txhaj tshuaj nyob hauv angular nrog piv txwv?

Dependency Txhaj nyob rau hauv Angular . Kev Txhaum Cai (DI) yog lub ntsiab lus tseem ceeb ntawm Angular 2+ thiab tso cai rau chav kawm tau txais kev vam khom los ntawm lwm chav kawm. Feem ntau nyob rau hauv Angular , kev vam meej txhaj tshuaj yog ua los ntawm kev txhaj tshuaj rau hauv chav kawm ua haujlwm lossis chav kawm module.

Ib yam li ntawd, dab tsi yog kev siv cov tshuaj tiv thaiv nyob rau hauv angular? Kev txhaj tshuaj tiv thaiv (DI), yog ib qho tseem ceeb daim ntawv thov tsim qauv. Angular muaj nws tus kheej DI moj khaum, uas yog feem ntau siv hauv kev tsim ntawm Angular daim ntawv thov kom lawv efficiency thiab modularity. Kev vam meej yog cov kev pabcuam lossis cov khoom uas ib chav kawm xav tau los ua nws txoj haujlwm.

Hais txog qhov no, dab tsi yog qhov kev txhaj tshuaj nyob hauv angular?

Kev Txhaum Cai (DI) yog tus qauv tsim software uas cuam tshuam nrog yuav ua li cas cov khoom tau tuav ntawm lawv kev vam khom . Cov AngularJS injector subsystem yog tus saib xyuas ntawm tsim cov khoom, daws lawv kev vam khom , thiab muab lawv rau lwm yam khoom raws li thov.

@inject hauv angular 2 yog dab tsi?

@ Txhaj () yog ib lub tswv yim rau kev cia Angular paub tias yuav tsum muaj parameter txhaj . Nws tuaj yeem siv tau zoo li: import {Component, Txhaj } los ntawm '@ lub kaum sab xis /core'; import {ChatWidget } los ntawm '../components/chat-widget'; ?

Pom zoo: