Top Related Projects
Deliver web apps with confidence 🚀
:star: Native angular select component
📝 JSON powered / Dynamic forms for Angular
Customizable admin dashboard template based on Angular 10+
Material design for AngularJS
Quick Overview
Angular-Formly is a JavaScript library that provides a simple and powerful way to build dynamic forms in Angular applications. It allows developers to define form fields and their behavior using a declarative approach, making it easier to manage complex forms and reduce boilerplate code.
Pros
- Declarative Approach: Angular-Formly uses a declarative syntax to define form fields, making it easier to manage and maintain complex forms.
- Flexibility: The library provides a wide range of built-in field types and supports custom field types, allowing developers to create highly customized forms.
- Validation: Angular-Formly integrates with Angular's built-in validation system, making it easy to add validation rules to form fields.
- Extensibility: The library is designed to be extensible, allowing developers to create their own custom field types and templates.
Cons
- Learning Curve: The library has a relatively steep learning curve, especially for developers who are new to Angular or declarative programming.
- Performance: Depending on the complexity of the form, Angular-Formly may have some performance issues, especially when dealing with large or dynamic forms.
- Dependency on Angular: Angular-Formly is tightly coupled with the Angular framework, which means that it may not be suitable for non-Angular projects.
- Limited Documentation: The project's documentation could be more comprehensive, making it harder for new users to get started.
Code Examples
Here are a few examples of how to use Angular-Formly:
- Defining a Simple Form:
import { Component } from '@angular/core';
import { FormlyFieldConfig } from '@ngx-formly/core';
@Component({
template: `
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<formly-form [form]="form" [fields]="fields" [model]="model">
</formly-form>
<button type="submit" [disabled]="form.invalid">Submit</button>
</form>
`
})
export class MyFormComponent {
form = new FormGroup({});
model = { email: 'test@example.com' };
fields: FormlyFieldConfig[] = [
{
key: 'email',
type: 'input',
templateOptions: {
label: 'Email',
placeholder: 'Enter your email',
required: true
}
}
];
onSubmit() {
console.log(this.model);
}
}
- Defining a Custom Field Type:
import { Component } from '@angular/core';
import { FieldType } from '@ngx-formly/core';
@Component({
selector: 'app-custom-field',
template: `
<input type="text" [formControl]="formControl" [placeholder]="to.placeholder">
`
})
export class CustomFieldComponent extends FieldType {}
// In your module:
import { FormlyModule } from '@ngx-formly/core';
import { CustomFieldComponent } from './custom-field.component';
@NgModule({
imports: [
FormlyModule.forRoot({
types: [
{ name: 'custom-field', component: CustomFieldComponent }
]
})
]
})
export class MyModule {}
- Handling Form Submission:
import { Component } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FormlyFieldConfig } from '@ngx-formly/core';
@Component({
template: `
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<formly-form [form]="form" [fields]="fields" [model]="model">
</formly-form>
<button type="submit" [disabled]="form.invalid">Submit</button>
</form>
`
})
export class MyFormComponent {
form = new FormGroup({});
model = { name: 'John Doe', email: 'john.doe@example.com' };
fields: FormlyFiel
Competitor Comparisons
Deliver web apps with confidence 🚀
Pros of Angular
- Comprehensive framework for building web applications
- Large ecosystem with extensive documentation and community support
- Powerful CLI for project scaffolding and development tasks
Cons of Angular
- Steeper learning curve due to its complexity
- Larger bundle size compared to more lightweight solutions
- Opinionated structure may be restrictive for some projects
Code Comparison
Angular (component example):
@Component({
selector: 'app-example',
template: `<form>
<input [(ngModel)]="name" name="name">
<button (click)="submit()">Submit</button>
</form>`
})
export class ExampleComponent {
name: string;
submit() { /* ... */ }
}
Angular Formly (form field definition):
fields: FormlyFieldConfig[] = [
{
key: 'name',
type: 'input',
templateOptions: {
label: 'Name',
placeholder: 'Enter your name',
required: true
}
}
];
Angular provides a full-featured framework for building web applications, while Angular Formly focuses specifically on simplifying form creation within Angular applications. Angular offers more comprehensive tools and features but comes with increased complexity, whereas Angular Formly provides a more streamlined approach to form management but with a narrower scope.
:star: Native angular select component
Pros of ng-select
- Focused on providing a powerful and flexible select component
- Extensive customization options for appearance and behavior
- Supports virtual scrolling for large datasets
Cons of ng-select
- Limited to select functionality, not a complete form solution
- May require additional setup for complex form scenarios
- Less integrated with other form elements compared to angular-formly
Code Comparison
ng-select:
<ng-select [items]="cities"
bindLabel="name"
bindValue="id"
[(ngModel)]="selectedCityId">
</ng-select>
angular-formly:
<formly-form [form]="form" [fields]="fields" [model]="model">
</formly-form>
Key Differences
- Scope: ng-select focuses on select inputs, while angular-formly is a comprehensive form solution
- Integration: angular-formly provides better integration with Angular's form ecosystem
- Flexibility: ng-select offers more customization for select inputs, while angular-formly provides flexibility for entire forms
Use Cases
- ng-select: Best for projects requiring advanced select functionality
- angular-formly: Ideal for complex form scenarios and rapid form development
Community and Maintenance
- Both projects have active communities and regular updates
- ng-select has more recent activity and a larger user base
- angular-formly has a longer history but less frequent updates
📝 JSON powered / Dynamic forms for Angular
Pros of ngx-formly
- Built specifically for Angular, offering better integration and performance
- More active development and maintenance
- Supports Angular's Reactive Forms out of the box
Cons of ngx-formly
- Steeper learning curve for developers new to Angular
- Less extensive documentation compared to angular-formly
Code Comparison
angular-formly:
$scope.fields = [
{
key: 'name',
type: 'input',
templateOptions: {
label: 'Name'
}
}
];
ngx-formly:
fields: FormlyFieldConfig[] = [
{
key: 'name',
type: 'input',
templateOptions: {
label: 'Name'
}
}
];
Both libraries use similar syntax for defining form fields, but ngx-formly leverages TypeScript for better type checking and IDE support. The main difference lies in how these fields are integrated into the component and template, with ngx-formly being more tightly coupled with Angular's architecture.
ngx-formly is generally considered the more modern and Angular-specific solution, while angular-formly is a more generic library that can be used with various JavaScript frameworks. Developers working on Angular projects may find ngx-formly more suitable due to its native integration and ongoing development tailored for the Angular ecosystem.
Customizable admin dashboard template based on Angular 10+
Pros of ngx-admin
- Comprehensive admin dashboard template with a wide range of UI components
- Built-in authentication, user management, and role-based access control
- Extensive documentation and regular updates
Cons of ngx-admin
- Steeper learning curve due to its complexity and extensive features
- May require more customization to fit specific project needs
- Larger bundle size compared to angular-formly
Code Comparison
ngx-admin:
<nb-card>
<nb-card-header>User Management</nb-card-header>
<nb-card-body>
<ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
</nb-card-body>
</nb-card>
angular-formly:
<form [formGroup]="form">
<formly-form [form]="form" [fields]="fields" [model]="model"></formly-form>
<button type="submit">Submit</button>
</form>
Key Differences
- ngx-admin focuses on providing a complete admin dashboard solution with various pre-built components and layouts
- angular-formly specializes in dynamic form generation and management
- ngx-admin offers a more opinionated structure, while angular-formly provides greater flexibility for form-specific implementations
Use Cases
- Choose ngx-admin for building full-featured admin panels or dashboards with complex UI requirements
- Opt for angular-formly when working on projects that primarily involve dynamic form generation and handling
Material design for AngularJS
Pros of Angular Material
- Comprehensive UI component library with a wide range of pre-built, customizable elements
- Follows Material Design principles, ensuring a modern and consistent look across applications
- Officially maintained by the Angular team, ensuring long-term support and compatibility
Cons of Angular Material
- Steeper learning curve due to the extensive API and configuration options
- Can be overkill for simple projects or when only a few components are needed
- Styling customization may require more effort to deviate from the Material Design aesthetic
Code Comparison
Angular Material (form field example):
<mat-form-field>
<mat-label>Favorite food</mat-label>
<input matInput placeholder="Ex. Pizza" value="Sushi">
</mat-form-field>
Angular Formly (form field example):
<formly-form [form]="form" [fields]="fields" [model]="model"></formly-form>
fields: FormlyFieldConfig[] = [
{
key: 'food',
type: 'input',
templateOptions: {
label: 'Favorite food',
placeholder: 'Ex. Pizza',
}
}
];
While Angular Material provides ready-to-use UI components, Angular Formly focuses on dynamic form generation with a more programmatic approach. Angular Material offers a wider range of components beyond forms, whereas Angular Formly specializes in form creation and management.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
angular-formly
THIS PROJECT NEEDS A MAINTAINER
angular-formly is an AngularJS module which has a directive to help customize and render JavaScript/JSON configured forms.
The formly-form
directive and the formlyConfig
service are very powerful and bring unmatched maintainability to your
application's forms.
<form name="vm.someForm" ng-submit="vm.handleSubmit()">
<formly-form model="vm.model" fields="vm.fields" options="vm.options">
<button type="submit" ng-disabled="vm.someForm.$invalid">Submit</button>
<button type="button" ng-click="vm.options.resetModel()">Reset</button>
</formly-form>
</form>
From there, it's just JavaScript. Allowing for DRY, maintainable, reusable forms.
IMPORTANT: This is the formly project for AngularJS (v1.x). If you're looking for an Angular (v2+) alternative, take a look at the ngx-formly project.
Learning
Egghead.io Lessons
I'm an egghead.io author and I have made a handful of lessons available there for free here
NG-NL Talk
Examples
The website is full of tons of examples.
More
Find more resources at learn.angular-formly.com
Documentation
Find all the documentation at docs.angular-formly.com.
Plugins
Find all the plugins at docs.angular-formly.com/page/plugins
Getting Help
Please don't file an issue unless you feel like you've found a bug or have a feature request. Instead, go to help.angular-formly.com and follow the instructions.
Roadmap
See the issues labeled enhancement
Contributing
Please see the CONTRIBUTING Guidelines.
Note: This projects adheres to a Code of Conduct.
Financial Support
Some have expressed a desire to contribute financially as a way of expressing gratitude. I appreciate anything you (or your company) would be willing to contribute :-) You can support me here. Thanks!
Bookmark Links
You can bookmark these :-)
- http://help.angular-formly.com
- http://question.angular-formly.com
- http://issue.angular-formly.com
- http://new-example.angular-formly.com
- http://egghead.angular-formly.com
- http://chat.angular-formly.com
- http://mailing-list.angular-formly.com
- http://learn.angular-formly.com
- http://questions.angular-formly.com
Thanks
A special thanks to Nimbly for creating angular-formly. This library is maintained (with love) by me, Kent C. Dodds. Thanks to all contributors!
Top Related Projects
Deliver web apps with confidence 🚀
:star: Native angular select component
📝 JSON powered / Dynamic forms for Angular
Customizable admin dashboard template based on Angular 10+
Material design for AngularJS
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot