fix(ivy): support injection flags for provider deps without new (#30216)

Previously, we were supporting injection flags for provider deps, but only
if they fit the format `new Optional()`. This commit fixes resolution of
provider deps to also support `Optional` (without the new). This keeps us
backwards compatible with what View Engine supported.

PR Close #30216
This commit is contained in:
Kara Erickson
2019-04-30 16:41:18 -07:00
parent b15a403c71
commit b1506a3271
2 changed files with 27 additions and 5 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Component, Directive, Inject, Injectable, InjectionToken, NgModule, forwardRef} from '@angular/core';
import {Component, Directive, Inject, Injectable, InjectionToken, Injector, NgModule, Optional, forwardRef} from '@angular/core';
import {TestBed, async, inject} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {onlyInIvy} from '@angular/private/testing';
@ -321,4 +321,25 @@ describe('providers', () => {
});
describe('flags', () => {
class MyService {
constructor(public value: OtherService|null) {}
}
class OtherService {}
it('should support Optional flag in deps', () => {
const injector =
Injector.create([{provide: MyService, deps: [[new Optional(), OtherService]]}]);
expect(injector.get(MyService).value).toBe(null);
});
it('should support Optional flag in deps without instantiating it', () => {
const injector = Injector.create([{provide: MyService, deps: [[Optional, OtherService]]}]);
expect(injector.get(MyService).value).toBe(null);
});
});
});