Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alorel/ngx-auto-id

Automatically generates and applies the id attribute on elements
https://github.com/alorel/ngx-auto-id

angular auto directive generator id id-generator ngx

Last synced: about 12 hours ago
JSON representation

Automatically generates and applies the id attribute on elements

Awesome Lists containing this project

README

        

# ngx-auto-id

Automatic ID generator for Angular

[![Build Status](https://travis-ci.com/Alorel/ngx-auto-id.svg?branch=2.0.0)](https://travis-ci.com/Alorel/ngx-auto-id)
[![Coverage Status](https://coveralls.io/repos/github/Alorel/ngx-auto-id/badge.svg?branch=2.0.0)](https://coveralls.io/github/Alorel/ngx-auto-id?branch=2.0.0)
[![Greenkeeper badge](https://badges.greenkeeper.io/Alorel/ngx-auto-id.svg)](https://greenkeeper.io/)

-----

# Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Automatically setting the default ID](#automatically-setting-the-default-id)
- [Controlling the ID prefix](#controlling-the-id-prefix)
- [Setting the default ID prefix](#setting-the-default-id-prefix)
- [Generating an ID without setting it](#generating-an-id-without-setting-it)
- [Typical usage within forms](#typical-usage-within-forms)

# Installation

```bash
npm install @aloreljs/ngx-auto-id@^2.0.0 # for Angular 8
npm install @aloreljs/ngx-auto-id@^1.0.0 # for Angular 7
```

# Usage

In whatever module you want to use the directive in:

```typescript
import {NgxAutoIdModule} from '@aloreljs/ngx-auto-id';

@NgModule({
imports: [NgxAutoIdModule]
})
export class MyFancyModule {}
```

## Automatically setting the default ID

```html



```

Outputs:

```html



```

## Controlling the ID prefix

```html



```

Outputs:

```html



```

### Setting the default ID prefix

You might want to replace the default "el-" prefix with your own; in this case, you should provide a value for
the NGX_AUTO_ID_DEFAULT_PREFIX token:

```typescript
import {NgModule} from '@angular/core';
import {NGX_AUTO_ID_DEFAULT_PREFIX} from '@aloreljs/ngx-auto-id';

@NgModule({
//... declarations etc
providers: [{
provide: NGX_AUTO_ID_DEFAULT_PREFIX,
useValue: 'my-prefix-'
}]
})
export class AppModule {

}
```

## Generating an ID without setting it

```html




```

Outputs:

```html




```

## Typical usage within forms

```html
Username:

```