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>
hasdata
as 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
leakScope
is true:But if
leakScope
is false:Because when the scope isn't leaked, the component's template does not see
exclamation
. The user content does not see the viewModel'ssubject
and uses the outer scope'ssubject
which is"World"
.Using the
leakScope: false
option is useful for hiding and protecting internal details ofcan.Component
, potentially preventing accidental clashes.