angular - Why all Directives and Pipes must be in module's declarations? -


any directives , pipes must in module's declarations. why can't added component level , instead have @ module level? why angular team has put restriction?

the angular team talked reasons deprecating component-level directives here when introduced modules.

deprecation

the ability import directives , pipes components deprecated. means after deprecation following properties removed: @component.directives , @component.pipes.

why

keeping @component.directives/pipes causes following issues:

two scopes

it creates 2 scopes: module scope , component scoped. module scoped similar how es6 modules work. result, easy explain user. have have dev ergonomics. component scope unique , harder explain.

breaks es6 mental model

having component scope breaks es6 mental model. in es6 use token have import module. tokens don't appear out of nowhere. easy explain use material component need import right module. because that's es6.

nobody use it

modules create small-enough scope avoid collisions, , more ergonomic. because using modules more ergonomic, component.directives option not used in practice. new angular user have use modules forms , common directives, natural me add own directives there.

there nothing stop having module exports single component, allow scope directives , pipes specific component, , more consistent , easier reason having components able own modules in circumstances.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -