Skip to content

Commit 302cace

Browse files
committed
feat(@schematics/angular): add skipSelector property to the component generator
Fix angular#14749
1 parent 11c8e93 commit 302cace

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

packages/schematics/angular/component/files/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';
22

3-
@Component({
4-
selector: '<%= selector %>',<% if(inlineTemplate) { %>
3+
@Component({<% if(!skipSelector) {%>
4+
selector: '<%= selector %>',<%}%><% if(inlineTemplate) { %>
55
template: `
66
<p>
77
<%= dasherize(name) %> works!

packages/schematics/angular/component/index_spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ describe('Component Schematic', () => {
325325
expect(content).toMatch(/selector: 'app-test'/);
326326
});
327327

328+
it('should respect the skipSelector option', async () => {
329+
const options = { ...defaultOptions, name: 'sub/test', skipSelector: true };
330+
appTree = await schematicRunner.runSchematicAsync('component', options, appTree)
331+
.toPromise();
332+
const content = appTree.readContent('/projects/bar/src/app/sub/test/test.component.ts');
333+
expect(content).not.toMatch(/selector: 'app-test'/);
334+
console.log(content);
335+
});
336+
328337
it('should respect the sourceRoot value', async () => {
329338
const config = JSON.parse(appTree.readContent('/angular.json'));
330339
config.projects.bar.sourceRoot = 'projects/bar/custom';

packages/schematics/angular/component/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
"format": "html-selector",
117117
"description": "The HTML selector to use for this component."
118118
},
119+
"skipSelector": {
120+
"type": "boolean",
121+
"default": false,
122+
"description": "Specifies if the component should have a selector or not."
123+
},
119124
"module": {
120125
"type": "string",
121126
"description": "The declaring NgModule.",

0 commit comments

Comments
 (0)