Khaki Calvin Sleeves Black Klein Womens 3 Floral 4 Sweaterdress Print 7HU8w7xq
Annabelle Round Casual Pocket Women Neck Royal 4 Dresses Sleeve s 3 ivory Casual Annabelle Royal s Pocket Sleeve 4 3 Round Dresses Women ivory Neck

Women Sleeve Round 4 Royal 3 s Dresses Neck Annabelle Pocket ivory Casual HFdpwqw

A constructor parameter decorator that marks a dependency as optional.

See also

Description

The DI framework provides null if the dependency is not found. For example, the following code allows the possibility of a null result:

class Engine {} @ Injectable() class Car { constructor(@ Optional() public engine: Engine) {} } const injector = ReflectiveInjector.resolveAndCreate([Car]); expect(injector.get(Car).engine).toBeNull();
      
      class Engine {}

@Injectable()
class Car {
  constructor(@Optional() public engine: Engine) {}
}

const injector = ReflectiveInjector.resolveAndCreate([Car]);
expect(injector.get(Car).engine).toBeNull();
    

Options