angular-cn/public/docs/js/latest/api/annotations/onChange-const.jade
2015-06-01 23:18:32 -07:00

35 lines
838 B
Plaintext

<h1>onChange</h1>
<h2>(const)</h2>
<div>
<p>Notify a directive when any of its bindings have changed.</p>
<p>This method is called right after the directive&#39;s bindings have been checked,
and before any of its children&#39;s bindings have been checked.</p>
<p>It is invoked only if at least one of the directive&#39;s bindings has changed.</p>
.l-main-section
h2 Example:
pre(class="prettyprint linenums")
code.
@Directive({
selector: '[class-set]',
properties: [
'propA',
'propB'
],
lifecycle: [onChange]
})
class ClassSet {
propA;
propB;
onChange(changes:{[idx: string, PropertyUpdate]}) {
// This will get called after any of the properties have been updated.
if (changes['propA']) {
// if propA was updated
}
if (changes['propA']) {
// if propB was updated
}
}
}
</div>