X Tutup
Skip to content

Commit a9aef8e

Browse files
committed
fix(core): set ViewEncapsulation.Emulated as the default again
Fixes #4494
1 parent 6fe8b85 commit a9aef8e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

modules/angular2/src/core/compiler/directive_metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class CompileTemplateMetadata {
6464
styleUrls?: string[],
6565
ngContentSelectors?: string[]
6666
} = {}) {
67-
this.encapsulation = encapsulation;
67+
this.encapsulation = isPresent(encapsulation) ? encapsulation : ViewEncapsulation.Emulated;
6868
this.template = template;
6969
this.templateUrl = templateUrl;
7070
this.styles = isPresent(styles) ? styles : [];

modules/angular2/test/core/compiler/directive_metadata_spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export function main() {
7676
});
7777

7878
describe('TemplateMetadata', () => {
79+
it('should use ViewEncapsulation.Emulated by default', () => {
80+
expect(new CompileTemplateMetadata({encapsulation: null}).encapsulation)
81+
.toBe(ViewEncapsulation.Emulated);
82+
});
83+
7984
it('should serialize with full data', () => {
8085
expect(CompileTemplateMetadata.fromJson(fullTemplateMeta.toJson()))
8186
.toEqual(fullTemplateMeta);

modules/angular2/test/core/compiler/template_compiler_spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {evalModule} from './eval_module';
2626
import {SourceModule, moduleRef} from 'angular2/src/core/compiler/source_module';
2727
import {XHR} from 'angular2/src/core/compiler/xhr';
2828
import {MockXHR} from 'angular2/src/core/compiler/xhr_mock';
29+
import {ViewEncapsulation} from 'angular2/src/core/render/api';
2930

3031
import {Locals} from 'angular2/src/core/change_detection/change_detection';
3132

@@ -283,22 +284,29 @@ export function main() {
283284
moduleId: THIS_MODULE_ID,
284285
exportAs: 'someExportAs'
285286
})
286-
@View({template: '<a [href]="someProp"></a>', styles: ['div {color: red}']})
287+
@View({
288+
template: '<a [href]="someProp"></a>',
289+
styles: ['div {color: red}'],
290+
encapsulation: ViewEncapsulation.None
291+
})
287292
class CompWithBindingsAndStyles {
288293
}
289294

290295
@Component({selector: 'tree', moduleId: THIS_MODULE_ID})
291-
@View({template: '<tree></tree>', directives: [TreeComp]})
296+
@View({template: '<tree></tree>', directives: [TreeComp], encapsulation: ViewEncapsulation.None})
292297
class TreeComp {
293298
}
294299

295300
@Component({selector: 'comp-url', moduleId: THIS_MODULE_ID})
296-
@View({templateUrl: 'compUrl.html'})
301+
@View({templateUrl: 'compUrl.html', encapsulation: ViewEncapsulation.None})
297302
class CompWithTemplateUrl {
298303
}
299304

300305
@Component({selector: 'comp-tpl', moduleId: THIS_MODULE_ID})
301-
@View({template: '<template><a [href]="someProp"></a></template>'})
306+
@View({
307+
template: '<template><a [href]="someProp"></a></template>',
308+
encapsulation: ViewEncapsulation.None
309+
})
302310
class CompWithEmbeddedTemplate {
303311
}
304312

0 commit comments

Comments
 (0)
X Tutup