@angular/core#Optional TypeScript Examples

The following examples show how to use @angular/core#Optional. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: pagination.directive.ts    From angular-custom-material-paginator with MIT License 6 votes vote down vote up
constructor(
    @Host() @Self() @Optional() private readonly matPag: MatPaginator,
    private readonly ViewContainer: ViewContainerRef,
    private readonly renderer: Renderer2
  ) {
    this.currentPage = 1;
    this.pageGapTxt = ['•••', '---'];
    this.showTotalPages = 3;
    this.checkPage = [0, 0, 0];
    // Display custom range label text
    this.matPag._intl.getRangeLabel = (page: number, pageSize: number, length: number): string => {
      const startIndex = page * pageSize;
      const endIndex = startIndex < length ?
        Math.min(startIndex + pageSize, length) :
        startIndex + pageSize;
      return length > 0 ? 'Showing ' + (startIndex + 1) + ' – ' + endIndex + ' of ' + length + ' records' : 'Showing 0 – 0 of 0 records';
    };
    // Subscribe to rerender buttons when next page and last page button is used
    this.matPag.page.subscribe((paginator: PageEvent) => {
      this.currentPage = paginator.pageIndex;
      this.matPag.pageIndex = paginator.pageIndex;
      this.initPageRange();
    });
  }
Example #2
Source File: accordion-item.component.ts    From canopy with Apache License 2.0 6 votes vote down vote up
constructor(
    @Optional() @SkipSelf() @Inject(LG_ACCORDION) public accordion: LgAccordionComponent,
    private selectionDispatcher: UniqueSelectionDispatcher,
    private cdr: ChangeDetectorRef,
  ) {
    this._removeSingleItemSelectionListener = selectionDispatcher.listen(
      (id: string, accordionId: string) => {
        if (
          accordion &&
          !accordion.multi &&
          accordion.id === accordionId &&
          this._id !== id
        ) {
          this.isActive = false;
          this.accordionPanelHeading.isActive = false;

          this.closed.emit();
          this.cdr.markForCheck();
        }
      },
    );
  }
Example #3
Source File: outletService.ts    From ngx-dynamic-hooks with MIT License 6 votes vote down vote up
constructor(
    @Optional() @Inject(DYNAMICHOOKS_GLOBALSETTINGS) private globalSettings: DynamicHooksGlobalSettings,
    private parserEntryResolver: ParserEntryResolver,
    private optionsResolver: OptionsResolver,
    private hooksReplacer: HooksReplacer,
    private componentCreator: ComponentCreator,
    private rendererFactory: RendererFactory2,
    private injector: Injector
  ) {
    this.renderer = rendererFactory.createRenderer(null, null);
  }
Example #4
Source File: attribution.service.ts    From barista with Apache License 2.0 6 votes vote down vote up
constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
        if (basePath) {
            this.basePath = basePath;
        }
        if (configuration) {
            this.configuration = configuration;
            this.basePath = basePath || configuration.basePath || this.basePath;
        }
    }
Example #5
Source File: base-cookie.service.ts    From svvs with MIT License 6 votes vote down vote up
constructor(
    @Inject(DOCUMENT) private document: Document,
    // eslint-disable-next-line @typescript-eslint/ban-types
    @Inject(PLATFORM_ID) private platformId: Object,
    @Inject(REQUEST) @Optional() private request: Request,
    @Inject(RESPONSE) @Optional() private response: Response,
  ) {
    this.isBrowser = isPlatformBrowser(platformId)
  }
Example #6
Source File: dynamic-browser-title.service.ts    From nghacks with MIT License 6 votes vote down vote up
constructor(
    @Optional() private _config: DynamicBrowserTitleConfig,
    private _router: Router,
    @Inject(DOCUMENT) private document: any,
    private _titleService: Title
  ) {
    this._document = this.document as Document;
    this.init();
    const titleElem: HTMLElement = this._document.querySelector('title');
    this._defaultTitle = titleElem?.innerText || '';
  }
Example #7
Source File: autocomplete.directive.ts    From alauda-ui with MIT License 6 votes vote down vote up
constructor(
    overlay: Overlay,
    viewContainerRef: ViewContainerRef,
    elRef: ElementRef<HTMLInputElement>,
    renderer: Renderer2,
    cdr: ChangeDetectorRef,
    ngZone: NgZone,
    @Optional()
    @Host()
    private readonly ngControl: NgControl,
  ) {
    super(overlay, viewContainerRef, elRef, renderer, cdr, ngZone);
    this.type = TooltipType.Plain;
    this.trigger = TooltipTrigger.Manual;
    this.position = 'bottom start';
    this.hideOnClick = true;
  }
Example #8
Source File: link-active.directive.ts    From router with MIT License 6 votes vote down vote up
constructor(
    public element: ElementRef,
    public router: Router,
    public renderer: Renderer2,
    @Optional()
    @Inject(LINK_ACTIVE_OPTIONS)
    private defaultActiveOptions: LinkActiveOptions,
    @Optional() private link: LinkTo
  ) {}
Example #9
Source File: scanner.service.ts    From RoboScan with GNU General Public License v3.0 6 votes vote down vote up
constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
        if (configuration) {
            this.configuration = configuration;
        }
        if (typeof this.configuration.basePath !== 'string') {
            if (typeof basePath !== 'string') {
                basePath = this.basePath;
            }
            this.configuration.basePath = basePath;
        }
        this.encoder = this.configuration.encoder || new CustomHttpParameterCodec();
    }
Example #10
Source File: title.service.ts    From blockcore-hub with MIT License 6 votes vote down vote up
constructor(
        private readonly router: Router,
        private setup: SetupService,
        @Inject(DOCUMENT) private readonly document: any,
        @Optional() @Inject(APP_TITLE) private readonly appTitle: any) {

        if (!TitleService.singletonInstance) {
            this.initialize();
            TitleService.singletonInstance = this;
        }

        return TitleService.singletonInstance;
    }
Example #11
Source File: dxc-button.component.ts    From halstack-angular with Apache License 2.0 6 votes vote down vote up
constructor(
    private utils: CssUtils,
    private cdRef: ChangeDetectorRef,
    @Optional() public bgProviderService?: BackgroundProviderService
  ) {
    this.bgProviderService.$changeColor.subscribe((value) => {
      if (value === "dark") {
        this.lightBackground = false;
        this.darkBackground = true;
      } else if (value === "light") {
        this.lightBackground = true;
        this.darkBackground = false;
      }
      this.className = `${this.getDynamicStyle(this.defaultInputs.getValue())}`;
    });
  }
Example #12
Source File: round-progress.service.ts    From Elastos.Essentials.App with MIT License 6 votes vote down vote up
constructor(@Optional() @Inject(DOCUMENT) document: any) {
    this.supportsSvg = !!(
      document &&
      document.createElementNS &&
      document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect
    );

    this.base = document && document.head.querySelector('base');
    this.hasPerf =
      typeof window !== 'undefined' &&
      window.performance &&
      window.performance.now &&
      typeof window.performance.now() === 'number';
  }
Example #13
Source File: title.service.ts    From EXOS-Core with MIT License 6 votes vote down vote up
constructor(
        private readonly router: Router,
        @Inject(DOCUMENT) private readonly document: any,
        @Optional() @Inject(APP_TITLE) private readonly appTitle: any) {

        if (!TitleService.singletonInstance) {
            this.initialize();
            TitleService.singletonInstance = this;
        }

        return TitleService.singletonInstance;
    }
Example #14
Source File: config.api.service.ts    From geonetwork-ui with GNU General Public License v2.0 6 votes vote down vote up
constructor(
    protected httpClient: HttpClient,
    @Optional() @Inject(BASE_PATH) basePath: string,
    @Optional() configuration: Configuration
  ) {
    if (configuration) {
      this.configuration = configuration
    }
    if (typeof this.configuration.basePath !== 'string') {
      if (typeof basePath !== 'string') {
        basePath = this.basePath
      }
      this.configuration.basePath = basePath
    }
    this.encoder = this.configuration.encoder || new CustomHttpParameterCodec()
  }