What Is New in AngularJS 1.2?
AngularJS 1.2 introduces significant new capabilities, performance refinements, and foundational changes for future development. This release focuses on enhancing the animation system, expression evaluation, and overall stability.
| Category | Key Highlights |
|---|---|
| New Features | Animation hooks, one-time binding ({{::expr}}), ngAnimate module, ngIf directive. |
| Improvements & Changes | Faster expression parsing, strict DI mode, $parse service improvements, ngRoute separated into its own module. |
| Breaking Changes | Changes to ngRepeat behavior for duplicate keys, input[number] validation, removal of ng:style in favor of ngStyle. |
| Deprecations | ng:style, ng:attr selectors; certain $compile and $animate behaviors. |
How does animation support improve in 1.2?
The ngAnimate module is now a core, optional module providing CSS and JavaScript animation hooks. This is a major architectural addition.
Directives like ngRepeat, ngShow, ngHide, and the new ngIf trigger animation events during DOM changes. In practice, you define CSS transitions or keyframe animations against classes like .ng-enter and .ng-leave.
This matters because it decouples animation logic from core Angular, making animations declarative and performant without cluttering your controllers.
What's the deal with one-time binding?
One-time binding ({{::expression}}) is a performance optimization that stops watching an expression after its value stabilizes.
The digest cycle skips these expressions, reducing watcher count. This is crucial for large lists rendered with ngRepeat. The binding becomes inert after the first non-undefined value is assigned, which is ideal for static data.
Use it when you know a value won't change. It's a simple syntax change with immediate performance wins in most real-world apps.
Why is ngRoute now a separate module?
The ngRoute module was extracted from the core angular.js file to reduce the default bundle size. You must now include angular-route.js and explicitly depend on the ngRoute module.
This change anticipates a more modular framework future. It allows teams that use third-party routers (like UI Router) to avoid loading unused code. The migration is straightforward but a common breaking change for upgrades.
What breaking changes affect ngRepeat the most?
ngRepeat now throws an error if it encounters duplicate keys across collection items. Previous versions would silently skip duplicate items.
This enforcement ensures track-by identity is correct, preventing subtle rendering bugs. You must ensure your track by expression or the default $id is unique. In practice, this catches many data preparation bugs early.
FAQ
Is one-time binding a silver bullet for performance?
No, but it's a highly effective tool. It reduces the number of active watchers, which directly speeds up digest cycles. Use it for values that are static after initial rendering, like constants or resolved data from a first API call.
Do I have to use ngAnimate now?
No, the ngAnimate module is completely optional. You only need to include angular-animate.js and add ngAnimate as a module dependency if you want to use the animation hooks. The core framework behavior remains unchanged without it.
My app broke on upgrade due to "duplicate key" errors. What's the fix?
Review the data collection you pass to ngRepeat. Ensure each item has a unique identifier. Use a specific track by expression, like track by item.id, to provide stable and unique keys, or deduplicate your source data.
What is "strict DI mode" and how do I enable it?
Strict DI mode, enabled via ng-strict-di on the app's root element or when manually bootstrapping, throws errors if dependency injection cannot be minification-safe. It forces you to use the array notation or $inject annotation everywhere, which is a good practice for production.
Why did my number input validation stop working?
AngularJS 1.2 changed input[number] to validate against the browser's native number input validation. This is more strict and aligns with HTML5. Non-numeric values now make the form control invalid. You may need to adjust your input type or use a custom validation directive for different numeric formats.