I would like to generate a component like this:
import { Component, OnInit } from '@angular/core';
@Component({
selector: '[appTest]', // <-- attribute selector
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss']
})
export class TestComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Normally, I would use the command
ng g c test
which generates a component with an element selector
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss']
})
export class TestComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
But when I try to specify the selector: ng g c test --selector="[appTest]"
it throws this error:
Schematic input does not validate against the Schema: {"style":"scss","spec":false,"selector":"[appTest]","name":"test","project":"client"}
Errors:
Data path ".selector" should match format "html-selector".
the --selector
cli option validates against a regex that doesn't allow these attribute selectors:
export const htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/;
(reference: Angular component naming limitations - 'selector [your component name] is invalid')
is there a way to generate via cli a component with a bracketed (like [appTest]
) attribute selector?