leakScope
{Boolean}
Allow reading the outer scope values from a component's template and a component's viewModel values in the user content.
{Boolean}Allow reading the outer scope values from a component's template and a component's viewModel values in the user content.
Use
A component's leakScope option controls if a component's template can access the component's outer scope and the user content can read the component's view model.
Lets define what outer scope, component's template and user content mean.
If I have a
<hello-world>component in a template like:The outer scope of
<hello-world>hasdataas its context. The user content of<hello-world>is the template between its tags. In this case, the user content is{{subject}}.Finally, if
<hello-world>is defined like:{{greeting}} <content/>{{exclamation}}represents the component's template.Example
If the following component is defined:
And used like so:
With the following data in the outer scope:
Will render the following if
leakScopeis true:But if
leakScopeis false:Because when the scope isn't leaked, the component's template does not see
exclamation. The user content does not see the viewModel'ssubjectand uses the outer scope'ssubjectwhich is"World".Using the
leakScope: falseoption is useful for hiding and protecting internal details ofcan.Component, potentially preventing accidental clashes.