Skip to content

Commit 86db69c

Browse files
BroccoMRHarrison
authored andcommitted
feature(generate): provide options to default encapsulation & change detection
Closes angular#2822 Close angular#2892
1 parent 2240672 commit 86db69c

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

packages/angular-cli/blueprints/component/files/__path__/__name__.component.ts

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

33
@Component({
44
selector: '<%= selector %>',<% if(inlineTemplate) { %>
@@ -9,7 +9,9 @@ import { Component, OnInit } from '@angular/core';
99
`,<% } else { %>
1010
templateUrl: './<%= dasherizedModuleName %>.component.html',<% } if(inlineStyle) { %>
1111
styles: []<% } else { %>
12-
styleUrls: ['./<%= dasherizedModuleName %>.component.<%= styleExt %>']<% } %>
12+
styleUrls: ['./<%= dasherizedModuleName %>.component.<%= styleExt %>']<% } %><% if(viewEncapsulation) { %>,
13+
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection) { %>,
14+
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
1315
})
1416
export class <%= classifiedModuleName %>Component implements OnInit {
1517

packages/angular-cli/blueprints/component/index.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ module.exports = {
1616
{ name: 'inline-template', type: Boolean, aliases: ['it'] },
1717
{ name: 'inline-style', type: Boolean, aliases: ['is'] },
1818
{ name: 'prefix', type: Boolean, default: true },
19-
{ name: 'spec', type: Boolean }
19+
{ name: 'spec', type: Boolean },
20+
{ name: 'view-encapsulation', type: String, aliases: ['ve'] },
21+
{ name: 'change-detection', type: String, aliases: ['cd'] }
2022
],
2123

2224
beforeInstall: function() {
@@ -68,6 +70,14 @@ module.exports = {
6870
options.spec :
6971
this.project.ngConfigObj.get('defaults.spec.component');
7072

73+
options.viewEncapsulation = options.viewEncapsulation !== undefined ?
74+
options.viewEncapsulation :
75+
this.project.ngConfigObj.get('defaults.viewEncapsulation');
76+
77+
options.changeDetection = options.changeDetection !== undefined ?
78+
options.changeDetection :
79+
this.project.ngConfigObj.get('defaults.changeDetection');
80+
7181
return {
7282
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
7383
flat: options.flat,
@@ -77,7 +87,9 @@ module.exports = {
7787
route: options.route,
7888
isAppComponent: !!options.isAppComponent,
7989
selector: this.selector,
80-
styleExt: this.styleExt
90+
styleExt: this.styleExt,
91+
viewEncapsulation: options.viewEncapsulation,
92+
changeDetection: options.changeDetection
8193
};
8294
},
8395

packages/angular-cli/lib/config/schema.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export interface CliConfig {
6060
styleExt?: string;
6161
prefixInterfaces?: boolean;
6262
poll?: number;
63+
viewEncapsulation?: string;
64+
changeDetection?: string;
6365
inline?: {
6466
style?: boolean;
6567
template?: boolean;

packages/angular-cli/lib/config/schema.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"items": {
3838
"type": "string"
3939
},
40-
"default": []
40+
"default": []
4141
},
4242
"index": {
4343
"type": "string",
@@ -144,6 +144,12 @@
144144
"poll": {
145145
"type": "number"
146146
},
147+
"viewEncapsulation": {
148+
"type": "string"
149+
},
150+
"changeDetection": {
151+
"type": "string"
152+
},
147153
"inline": {
148154
"type": "object",
149155
"properties": {

0 commit comments

Comments
 (0)