Skip to content

makseo/angular-required

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Angular Required

Angular 2+ decorator to make @Input required

NPM

Install with npm:

npm install angular-required --save

Usage example

For example, to display the map it is necessary to specify latitude and longitude. If you forgot to specify one of the parameters, then you will see the corresponding error message in the console.

alt text

app.component.ts

@Component({
  selector: 'app-root',
  template: '<app-map [latitude]="29.58"></app-map>',
})
export class AppComponent {}

map.component.ts

@Component({
  selector: 'app-map',
  template: `
    <div>Latitude: {{latitude}}</div>
    <div>Longitude: {{longitude}}</div>
    <div *ngIf="zoom">Zoom: {{zoom}}</div>
  `,
})
export class MapComponent {
  @Input() @Required() latitude: number;
  @Input() @Required() longitude: number;
  @Input() zoom: number;
}

About

Angular 2+ decorator to make @input required

Resources

Stars

Watchers

Forks

Packages

No packages published