background w/ default color', () => {
const dir = des[1].injector.get(HighlightDirective) as HighlightDirective;
- expect(des[1].styles['backgroundColor']).toBe(dir.defaultColor);
+ const bgColor = des[1].nativeElement.style.backgroundColor;
+ expect(bgColor).toBe(dir.defaultColor);
});
it('should bind background to value color', () => {
@@ -65,17 +67,19 @@ describe('HighlightDirective', () => {
expect(input.style.backgroundColor).toBe('green', 'changed backgroundColor');
});
- // customProperty tests
- it('all highlighted elements should have a true customProperty', () => {
- const allTrue = des.map(de => !!de.properties['customProperty']).every(v => v === true);
- expect(allTrue).toBe(true);
- });
it('bare
should not have a customProperty', () => {
expect(bareH2.properties['customProperty']).toBeUndefined();
});
// #enddocregion selected-tests
+ // Removed on 12/02/2016 when ceased public discussion of the `Renderer`. Revive in future?
+ // // customProperty tests
+ // it('all highlighted elements should have a true customProperty', () => {
+ // const allTrue = des.map(de => !!de.properties['customProperty']).every(v => v === true);
+ // expect(allTrue).toBe(true);
+ // });
+
// injected directive
// attached HighlightDirective can be injected
it('can inject `HighlightDirective` in 1st
', () => {
diff --git a/public/docs/_examples/testing/ts/app/shared/highlight.directive.ts b/public/docs/_examples/testing/ts/app/shared/highlight.directive.ts
index 4a45c8d5aa..20901878c4 100644
--- a/public/docs/_examples/testing/ts/app/shared/highlight.directive.ts
+++ b/public/docs/_examples/testing/ts/app/shared/highlight.directive.ts
@@ -1,5 +1,5 @@
// #docregion
-import { Directive, ElementRef, Input, OnChanges, Renderer } from '@angular/core';
+import { Directive, ElementRef, Input, OnChanges } from '@angular/core';
@Directive({ selector: '[highlight]' })
/** Set backgroundColor for the attached element to highlight color
@@ -10,13 +10,11 @@ export class HighlightDirective implements OnChanges {
@Input('highlight') bgColor: string;
- constructor(private renderer: Renderer, private el: ElementRef) {
- renderer.setElementProperty(el.nativeElement, 'customProperty', true);
+ constructor(private el: ElementRef) {
+ el.nativeElement.style.customProperty = true;
}
ngOnChanges() {
- this.renderer.setElementStyle(
- this.el.nativeElement, 'backgroundColor',
- this.bgColor || this.defaultColor );
+ this.el.nativeElement.style.backgroundColor = this.bgColor || this.defaultColor;
}
}
diff --git a/public/docs/ts/latest/guide/attribute-directives.jade b/public/docs/ts/latest/guide/attribute-directives.jade
index 7375c6aa66..911e815b02 100644
--- a/public/docs/ts/latest/guide/attribute-directives.jade
+++ b/public/docs/ts/latest/guide/attribute-directives.jade
@@ -78,7 +78,6 @@ block highlight-directive-1
1. `ElementRef` [injects](dependency-injection.html) into the directive's constructor
so the code can access the DOM element.
1. `Input` allows data to flow from the binding expression into the directive.
- 1. `Renderer` allows the code to change the DOM element's style.
Next, the `@Directive` decorator function contains the directive metadata in a configuration object
as an argument.
@@ -107,10 +106,10 @@ p
| Exporting #[code HighlightDirective] makes it accessible to other components.
:marked
Angular creates a new instance of the directive's controller class for
- each matching element, injecting an Angular `ElementRef` and `Renderer`
+ each matching element, injecting an Angular `ElementRef`
into the constructor.
`ElementRef` is a service that grants direct access to the DOM element
- through its `nativeElement` property and `Renderer` allows the code to set the element style.
+ through its `nativeElement` property.
.l-main-section
a#apply-directive
diff --git a/public/docs/ts/latest/guide/testing.jade b/public/docs/ts/latest/guide/testing.jade
index e85bb41fc3..db9555431e 100644
--- a/public/docs/ts/latest/guide/testing.jade
+++ b/public/docs/ts/latest/guide/testing.jade
@@ -1578,13 +1578,16 @@ figure.image-display
in `By.css('h2:not([highlight])')` helps find `
` elements that _do not_ have the directive.
`By.css('*:not([highlight])')` finds _any_ element that does not have the directive.
+// Removed on 12/02/2016 when ceased public discussion of the `Renderer`. Revive in future?
* `DebugElement.styles` affords access to element styles even in the absence of a real browser, thanks to the `DebugElement` abstraction.
But feel free to exploit the `nativeElement` when that seems easier or more clear than the abstraction.
+:marked
* Angular adds a directive to the injector of the element to which it is applied.
The test for the default color uses the injector of the 2nd `
` to get its `HighlightDirective` instance
and its `defaultColor`.
-
+
+// Removed on 12/02/2016 when ceased public discussion of the `Renderer`. Revive in future?
* `DebugElement.properties` affords access to the artificial custom property that is set by the directive.
a(href="#top").to-top Back to top
@@ -1875,8 +1878,7 @@ table
:marked
The testing shims (`karma-test-shim`, `browser-test-shim`)
establish the [initial test environment](##testbed-initTestEnvironment) and a default testing module.
- The default testing module is configured with basic declaratives and some Angular service substitutes (e.g. `DebugDomRender`)
- that every tester needs.
+ The default testing module is configured with basic declaratives and some Angular service substitutes that every tester needs.
Call `configureTestingModule` to refine the testing module configuration for a particular set of tests
by adding and removing imports, declarations (of components, directives, and pipes), and providers.
@@ -2214,49 +2216,50 @@ table
+makeExample('testing/ts/app/hero/hero-list.component.spec.ts', 'by', 'app/hero/hero-list.component.spec.ts')(format=".")
-#renderer-tests
-:marked
- Many custom application directives inject the `Renderer` and call one of its `set...` methods.
-
- The test environment substitutes the `DebugDomRender` for the runtime `Renderer`.
- The `DebugDomRender` updates additional dictionary properties of the `DebugElement`
- when something calls a `set...` method.
-
- These dictionary properties are primarily of interest to authors of Angular DOM inspection tools
- but they may provide useful insights to testers as well.
+// Removed on 12/02/2016 when ceased public discussion of the `Renderer`. Revive in future?
+ #renderer-tests
+ :marked
+ Many custom application directives inject the `Renderer` and call one of its `set...` methods.
-table
- tr
- th Dictionary
- th Description
- tr
- td(style="vertical-align: top") properties
- td
- :marked
- Updated by `Renderer.setElementProperty`.
- Many Angular directives call it, including `NgModel`.
- tr
- td(style="vertical-align: top") attributes
- td
- :marked
- Updated by `Renderer.setElementAttribute`.
- Angular `[attribute]` bindings call it.
- tr
- td(style="vertical-align: top") classes
- td
- :marked
- Updated by `Renderer.setElementClass`.
- Angular `[class]` bindings call it.
- tr
- td(style="vertical-align: top") styles
- td
- :marked
- Updated by `Renderer.setElementStyle`.
- Angular `[style]` bindings call it.
-:marked
- Here's an example of `Renderer` tests from the live "Specs Bag" sample.
+ The test environment substitutes the `DebugDomRender` for the runtime `Renderer`.
+ The `DebugDomRender` updates additional dictionary properties of the `DebugElement`
+ when something calls a `set...` method.
+
+ These dictionary properties are primarily of interest to authors of Angular DOM inspection tools
+ but they may provide useful insights to testers as well.
+
+ table
+ tr
+ th Dictionary
+ th Description
+ tr
+ td(style="vertical-align: top") properties
+ td
+ :marked
+ Updated by `Renderer.setElementProperty`.
+ Many Angular directives call it, including `NgModel`.
+ tr
+ td(style="vertical-align: top") attributes
+ td
+ :marked
+ Updated by `Renderer.setElementAttribute`.
+ Angular `[attribute]` bindings call it.
+ tr
+ td(style="vertical-align: top") classes
+ td
+ :marked
+ Updated by `Renderer.setElementClass`.
+ Angular `[class]` bindings call it.
+ tr
+ td(style="vertical-align: top") styles
+ td
+ :marked
+ Updated by `Renderer.setElementStyle`.
+ Angular `[style]` bindings call it.
+ :marked
+ Here's an example of `Renderer` tests from the live "Specs Bag" sample.
-+makeExample('testing/ts/app/bag/bag.spec.ts', 'debug-dom-renderer')(format=".")
+ +makeExample('testing/ts/app/bag/bag.spec.ts', 'dom-attributes')(format=".")
a(href="#top").to-top Back to top