fix(compiler): work well with forwardRef
with useValue
/ useFactory
The new expression lowering lowers everything after `useValue` / `useFactory` into a separate exported variable. If the value was a `forwardRef`, this was passed to the runtime and resulted in errors. This change unwraps `forwardRef`s during runtime again. Note: we can’t unwrap the `forwardRef` into an exported variable during compile time, as this would defeat the purpose of the `forwardRef` in referring to something that can’t be referred to at this position.
This commit is contained in:

committed by
Victor Berchet

parent
e31a76ce24
commit
1dacae2c3c
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import * as common from '@angular/common';
|
||||
import {CUSTOM_ELEMENTS_SCHEMA, Component, Directive, EventEmitter, Inject, InjectionToken, NgModule, Output} from '@angular/core';
|
||||
import {CUSTOM_ELEMENTS_SCHEMA, Component, Directive, EventEmitter, Inject, InjectionToken, NgModule, Output, forwardRef} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
import {wrapInArray} from './funcs';
|
||||
@ -18,7 +18,7 @@ export const SOME_INJECTON_TOKEN = new InjectionToken('injectionToken');
|
||||
selector: 'comp-providers',
|
||||
template: '',
|
||||
providers: [
|
||||
{provide: 'strToken', useValue: 'strValue'},
|
||||
{provide: 'strToken', useValue: forwardRef(() => 'strValue')},
|
||||
{provide: SOME_INJECTON_TOKEN, useValue: 10},
|
||||
{provide: 'reference', useValue: common.NgIf},
|
||||
{provide: 'complexToken', useValue: {a: 1, b: ['test', SOME_INJECTON_TOKEN]}},
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ApplicationRef, NgModule} from '@angular/core';
|
||||
import {ApplicationRef, NgModule, forwardRef} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {MATERIAL_SANITY_CHECKS, MdButtonModule} from '@angular/material';
|
||||
import {ServerModule} from '@angular/platform-server';
|
||||
@ -68,7 +68,7 @@ export {SomeModule as JitSummariesSomeModule} from './jit_summaries';
|
||||
],
|
||||
providers: [
|
||||
SomeService,
|
||||
{provide: CUSTOM, useValue: {name: 'some name'}},
|
||||
{provide: CUSTOM, useValue: forwardRef(() => ({name: 'some name'}))},
|
||||
// disable sanity check for material because it throws an error when used server-side
|
||||
// see https://github.com/angular/material2/issues/6292
|
||||
{provide: MATERIAL_SANITY_CHECKS, useValue: false},
|
||||
|
Reference in New Issue
Block a user