one-time binding (::) in modern Angular
Angular has no :: syntax and does not need one. Bindings are compiled code with no watcher list, and OnPush with signals limits checks to the components whose data changed.
Before · AngularJS
<h1>{{ ::vm.title }}</h1>
<ul>
<li ng-repeat="c in ::vm.countries">{{ ::c.name }}</li>
</ul>
<span ng-class="::{ premium: vm.user.premium }">{{ ::vm.user.plan }}</span>After · Angular@Component({
selector: 'app-country-list',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<h1>{{ title() }}</h1>
@for (c of countries(); track c.id) {
<li>{{ c.name }}</li>
}
`,
})
export class CountryListComponent {
title = input.required<string>();
countries = input.required<Country[]>();
}What changes
- Remove the :: prefix; the binding itself stays the same.
- ChangeDetectionStrategy.OnPush skips a component until an input changes, an event fires inside it, or a signal it reads changes.
- Static lists rendered with @for and a track expression are not re-created when nothing changed.
Migration tip. Look for places where :: was used on purpose to freeze a value while the model kept changing. Those need an explicit copy taken once in the component, because a normal binding will now update.
Related
- ng-change / ng-blur / ng-keyup
- ng-disabled / ng-readonly / ng-checked
- ng-src / ng-href / ng-srcset
- ngMessages
Planning a migration or a micro-frontend platform?
In a 20-minute call you describe your situation and I tell you how I'd approach it. If it isn't worth doing yet, I'll say so.
Message me on LinkedIn