generate component with encapsulation inconsistent behavior
See original GitHub issueBug Report or Feature Request (mark with an x
)
- [ x ] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@angular/cli: 1.5.0
@angular/material: 2.0.0-beta.7
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.1
typescript: 2.4.1
webpack-bundle-analyzer: 2.8.3
webpack: 3.8.1
Repro steps path 1.
- Add the following to your
.angular-cli.json
"component": {
"viewEncapsulation": "None"
},
- run
ng g c my
Result:
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-my',
templateUrl: './myComponent.component.html',
styleUrls: ['./myComponent.component.scss']
})
export class MyComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Repro steps path 2.
- With default
.angular-cli.json
ng g component my -ve None
Result:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my',
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class MyComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
Desired functionality.
When running via the command flag the attribute on the metadata is set, when running via the cli option the import is added but the metadata is not set. The behavior for both should apply the metadata and add the import.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:11 (4 by maintainers)
Top Results From Across the Web
A Step by Step Guide to Encapsulation, Generation, and ...
Hope this gives you some idea on component encapsulation methods. ... we start the component conversion, make sure to check the behaviour.
Read more >Reactive Encapsulation: Reusable Components in React
Let's walk though some of these strategies to make our components more reusable. Strategy 1: Inversion of Control. While it's always easier to ......
Read more >Encapsulation in Object Oriented Programming (OOPS)
Encapsulation is one of the fundamental concepts in OOP that bundles data and associated methods that operate on that data into a single...
Read more >Must Dependency Injection come at the expense of ...
Encapsulation is only broken if a class has both the responsibility to create the object (which requires knowledge of implementation details) ...
Read more >Encapsulation and Inheritance in Object-Oriented ...
Class definitions share common components using inheritance. ... The first case arises when the behavior of the objects is incompatible with the.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mtpultz the PR (https://github.com/angular/devkit/commit/a8a6559649c8815b2b24561bd6ef00e4e4ad4ab8) only fixes the broken import.
as @gkalpak figured out (see https://github.com/angular/angular-cli/issues/8398#issuecomment-343424366)
… for some strange reason the default value in the schematics configuration is set to
None
. Which makes no sense, IMHO. 😕Hi @zackarychapple, that comment was for @zhuravlyov since he was adding it to
angular.cli.json
and still gettingViewEncapsulation.None
added to his components, and he appears to be trying to not have it added so he needs to set it to:Your bug report seems to be focused on
ViewEncapsulation
should be added usingangular.cli.json
defaults or using the CLI flag. I’m using Angular CLI v1.5 as well and once added toangular.cli.json
it outputsNone
if that’s what I’ve chosen, or ifEmulated
doesn’t add anything since that is Angular’s defaultViewEncapsulation
, and the same if just added via the terminal.Angular CLI v1.5 Results
Based on Angular CLI v1.5 it seems the logic is reversed for importing
ViewEncapsulation
betweenNone
andEmulated
otherwise it seems to work as advertised. See the resulting outputs based just using the terminal and setting theViewEncapsulation
inangular.cli.json
.No changes to angular.cli.json
ng generate component Example1
has an issue ofViewEncapsulation
is not being imported, but adds the proper metadata since for whatever reason the Angular CLI has a different default then Angularng generate component Example2 -ve=None
has an issue ofViewEncapsulation
is not being imported, but adds the proper metadatang generate component Example3 -ve=Emulated
has an issue ofViewEncapsulation
is being added when it shouldn’t. As expected it does not add the metadata since this is Angular’s default so not required.Changes to
angular.cli.json
defaultsng generate component Example4
has an issue ofViewEncapsulation
not being imported, when it is needed whenNone
set as default inangular.cli.json
, which requires metadata to be set.ng generate component Example5
has an issue ofViewEncapsulation
being imported when it shouldn’t since the default ofEmulated
is set inangular.cli.json
, which doesn’t require metadata to be set.