Skip to content

Feature Request : permit to configure directive and component prefix by module #3452

Closed
@nweldev

Description

@nweldev

OS?

All

Versions.

angular-cli: 1.0.0-beta.22-1
node: 6.9.1
os: win32 x64

Why?

Using different components and directives prefixes for each module :

  1. improve readability (exemple : 'hero-info' instead of 'app-hero-info').
  2. ease moving / copying an existing module to a separate application (it shouldn't require to change all components and directive prefixes).

Bonus : I would be glad to help to implement that.

Use case

ng new cli-22-1-test
cd cli-22-1-test
ng g m hero

Now, generate a new component : ng g c hero/info.

Generated hero/info/info.component.ts :

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-info',
  templateUrl: './info.component.html',
  styleUrls: ['./info.component.css']
})
export class InfoComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

Here, the selector should be "hero-info" instead of "app-info".

Extra

Generated hero/hero-component.ts :

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-hero',
  templateUrl: './hero.component.html',
  styleUrls: ['./hero.component.css']
})
export class HeroComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

Here, the selector could be "hero-root" instead of "app-hero".

Option 1

Permit to override the root angular-cli.json file with an angular-cli.json file per module.

Following the previous example, we would create a src/app/hero/angular-cli.json file :

{
  "apps": [
    {
      "prefix": "hero"
    }
  ]
}

Of course, only few options should be available.

Option 2

Add a apps[0].modules config parameter for that.

Example :

{
  "project": {
    "version": "1.0.0-beta.22-1",
    "name": "cli-22-1"
  },
  "apps": [
    {
      ...
      modules: {
          "hero" : {
              "prefix": "hero"
           }
      }
    }
  ],
  "addons": [],
  "packages": [],
  ...
  }
}

Option 3

Change apps[0].prefix: string to :

prefixes: {
     "default": "app",
     "hero": "hero"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIssue that requests a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions