mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
feed89e83c
This is after we've slightly changed a rule in #66056
(cherry picked from commit 6270bba056)
ngStyle to style migration
This schematic helps developers to convert ngStyle directive usages to style bindings where possible.
How to run this migration?
The migration can be run using the following command:
ng generate @angular/core:ngstyle-to-style
By default, the migration will go over the entire application. If you want to apply this migration to a subset of the files, you can pass the path argument as shown below:
ng generate @angular/core:ngstyle-to-style --path src/app/sub-component
How does it work?
The schematic will attempt to find all the places in the templates where the directive is used and check if it can be converted to [style].
Example:
<!-- Before -->
<div [ngStyle]="{'background-color': 'red'}">
<!-- After -->
<div [style]="{'background-color': 'red'}"></div>
</div>