@angular/core#SimpleChanges TypeScript Examples

The following examples show how to use @angular/core#SimpleChanges. 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: expandable-header.directive.ts    From Uber-ServeMe-System with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    if(this.scrollContent && this.config) {
      this.scrollContent.scrollEvents = true;

      let scrollStartFunc = async (ev) => {
        const el = await this.scrollContent.getScrollElement();
        this.contentHeight = el.offsetHeight;
        this.scrollHeight = el.scrollHeight;
        if (this.config.maxValue === undefined) {
          this.config.maxValue = this.element.nativeElement.offsetHeight;
        }
        this.lastScrollPosition = el.scrollTop;
      };

      if(this.scrollContent && this.scrollContent instanceof IonContent) {
        this.scrollContent.ionScrollStart.subscribe(scrollStartFunc);
        this.scrollContent.ionScroll.subscribe(async (ev) => this.adjustElementOnScroll(ev));
        this.scrollContent.ionScrollEnd.subscribe(async (ev) => this.adjustElementOnScroll(ev));

      } else if(this.scrollContent instanceof HTMLElement) {
        (this.scrollContent as HTMLElement).addEventListener('ionScrollStart', scrollStartFunc);
        (this.scrollContent as HTMLElement).addEventListener('ionScroll',async (ev) => this.adjustElementOnScroll(ev));
        (this.scrollContent as HTMLElement).addEventListener('ionScrollEnd',async (ev) => this.adjustElementOnScroll(ev));
      }
    }
  }
Example #2
Source File: ngx-splide.component.ts    From ngx-splide with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges)
    {
        if (!this.splide) {
            return;
        }

        if (changes['selectedSlideIndex']) {
            const currentIndex = changes['selectedSlideIndex'].currentValue;
            if (currentIndex !== this.splide.index) {
                this.splide.go(currentIndex);
            }
        }

        if (changes['options']) {
            this.splide.options = changes['options'].currentValue;
        }
    }
Example #3
Source File: window.component.ts    From nica-os with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    const {currentWindow} = changes;
    if (
      currentWindow &&
      currentWindow.previousValue &&
      currentWindow.currentValue.properties.fullScreen !== currentWindow.previousValue.properties.fullScreen
    ) {
      this.handleChanges(currentWindow.currentValue.properties.fullScreen);
    }
  }
Example #4
Source File: highlight.directive.ts    From Angular-Cookbook with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    if (changes.highlightText.firstChange) {
      this.originalHTML = this.el.nativeElement.innerHTML;
      return;
    }
    const { currentValue } = changes.highlightText;
    if (currentValue) {
      const regExp = new RegExp(`(${currentValue})`, 'gi');
      this.el.nativeElement.innerHTML = this.originalHTML.replace(
        regExp,
        `<span style="background-color: ${this.highlightColor}">\$1</span>`
      );
    } else {
      this.el.nativeElement.innerHTML = this.originalHTML;
    }
    console.log(currentValue);
  }
Example #5
Source File: ngx-gallery-thumbnails.component.ts    From ngx-gallery-9 with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
      if (changes['selectedIndex']) {
          this.validateIndex();
      }

      if (changes['swipe']) {
          this.helperService.manageSwipe(this.swipe, this.elementRef,
          'thumbnails', () => this.moveRight(), () => this.moveLeft());
      }

      if (this.images) {
          this.remainingCountValue = this.images.length - (this.rows * this.columns);
      }
  }
Example #6
Source File: attack-order.component.ts    From colo-calc with Do What The F*ck You Want To Public License 6 votes vote down vote up
// @TODO: show range
  // @TODO: nicer img look
  // @TODO: show in a max size box, use fit-content to resize things and max-values to keep things sane
  ngOnChanges(changes: SimpleChanges): void {
    console.log('changes!');
    if (this.textMode) {
      this.textEvents = this.events.map((event) => this.toStringEvent(event));
    } else {
      this.toImgEvents(this.events);
    }
  }
Example #7
Source File: potential-addon-table-cell.component.ts    From WowUp with GNU General Public License v3.0 6 votes vote down vote up
public ngOnChanges(changes: SimpleChanges): void {
    if (changes.clientType) {
      if (this.addon.latestAddonChannel !== this.channel) {
        this._latestChannelType = this.addon.latestAddonChannel;
      } else {
        this._latestChannelType = this._getAddonListItemFileProp.transform(
          this.addon,
          "channelType",
          this.channel
        ) as AddonChannelType;
      }

      this._requiredDependencies = this.getRequiredDependencies();
    }
  }
Example #8
Source File: country-orders-chart.component.ts    From ngx-admin-dotnet-starter with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    if (changes.data && !changes.data.isFirstChange()) {
      this.echartsInstance.setOption({
        series: [
          {
            data: this.data.map(v => this.maxValue),
          },
          {
            data: this.data,
          },
          {
            data: this.data,
          },
        ],
      });
    }
  }
Example #9
Source File: drawer.component.ts    From alauda-ui with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    const { visible } = changes;
    if (visible) {
      const value = visible.currentValue;
      if (value) {
        this.open();
      } else {
        this.dispose();
      }
    }
  }
Example #10
Source File: mat-fab-menu.component.ts    From fab-menu with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    if (changes.direction && !changes.direction.firstChange) {
      this.direction = changes.direction.currentValue;
      this.adjustLayout();
    }

    if (changes.color && !changes.color.firstChange) {
      this.color = changes.color.currentValue;
    }

    if (changes.fabButtons && !changes.fabButtons.firstChange) {
      this.fabButtons = changes.fabButtons.currentValue;
    }
  }
Example #11
Source File: image-crop.component.ts    From ASW-Form-Builder with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
        this.onChangesUpdateSettings(changes);
        this.onChangesInputImage(changes);

        if (this.loadedImage?.original.image.complete && (changes.containWithinAspectRatio || changes.canvasRotation)) {
            this.loadImageService
                .transformLoadedImage(this.loadedImage, this.settings)
                .then((res) => this.setLoadedImage(res))
                .catch((err) => this.loadImageError(err));
        }
        if (changes.cropper || changes.maintainAspectRatio || changes.aspectRatio) {
            this.setMaxSize();
            this.setCropperScaledMinSize();
            this.setCropperScaledMaxSize();
            if (this.maintainAspectRatio && (changes.maintainAspectRatio || changes.aspectRatio)) {
                this.resetCropperPosition();
            } else if (changes.cropper) {
                this.checkCropperPosition(false);
                this.doAutoCrop();
            }
            this.cd.markForCheck();
        }
        if (changes.transform) {
            this.transform = this.transform || {};
            this.setCssTransform();
            this.doAutoCrop();
        }
    }
Example #12
Source File: ion-intl-tel-input.component.ts    From ion-intl-tel-input with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    if (
      this.countries &&
      changes.defaulyCountryisoCode &&
      changes.defaulyCountryisoCode.currentValue !==
        changes.defaulyCountryisoCode.previousValue
    ) {
      this.setCountry(changes.defaulyCountryisoCode.currentValue);
    }
  }
Example #13
Source File: file-system-tree-explorer.component.ts    From qbit-matUI with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    if(changes.directories) {
      this.directories = changes.directories.currentValue;
      this._updateData();
    }

    if(changes.showProgress) { this.showProgress = changes.showProgress.currentValue; }
    if(changes.allowSetPriority) { this.allowSetPriority = changes.allowSetPriority.currentValue }
  }
Example #14
Source File: app-bar.component.ts    From angular-component-library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
        if (changes.variant) {
            this._resizeOnModeChange();
        }
        this.useDefaultCollapsedHeight = isNaN(this.collapsedHeight) || this.collapsedHeight === 0;
        this.expandedHeight = Number(this.expandedHeight);
        this.collapsedHeight = Number(this.collapsedHeight);

        if (changes.scrollContainerClassName || changes.scrollContainerId || changes.scrollContainerElement) {
            this._listenForScrollEvents();
        }

        this._ref.detectChanges();
    }
Example #15
Source File: cloudflare-stream.component.ts    From stream-angular with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    // ngOnChanges fires when the component mounts but before the view
    // is initialized, so we need to bail when this fires for the first
    // time.
    if (!this.streamEl) {
      return;
    }
    // convert SimpleChanges into a Record that has currentValues to be
    // synced onto streamEl
    this.syncProperties(
      Object.keys(changes).reduce(
        (acc, key) => ({
          ...acc,
          [key]: changes[key].currentValue,
        }),
        {}
      )
    );
  }
Example #16
Source File: cometchat-conversation-list-item.component.ts    From cometchat-pro-angular-ui-kit with MIT License 6 votes vote down vote up
ngOnChanges(change: SimpleChanges) {
    try {
      if (change[enums.CONVERSATION_DETAILS]) {
        if (
          change[enums.CONVERSATION_DETAILS].currentValue !==
          change[enums.CONVERSATION_DETAILS].previousValue
        ) {
          this.getLastMessage(change[enums.CONVERSATION_DETAILS].currentValue);
          this.getLastMessageTimestamp(
            change[enums.CONVERSATION_DETAILS].currentValue
          );
          this.getName(change[enums.CONVERSATION_DETAILS].currentValue);
        }
      }
    } catch (error) {
      logger(error);
    }
  }
Example #17
Source File: json-schema-form.component.ts    From json-schema-form with Apache License 2.0 6 votes vote down vote up
/**
   * if the schema changes from the outside,
   * reset the component state wrt. errors and the choices cache
   */
  ngOnChanges(changes: SimpleChanges): void {
    if (changes.value && !changes.value.isFirstChange() && this.getLayout() === 'autocomplete') {
      // make sure autocomplete form control picks up external changes
      this.control.setValue(changes.value.currentValue);
    }

    if (changes.schema) {
      if (changes.schema.previousValue) {
        this.rootSchema = null;
        if (this.widgetHost.viewContainerRef) {
          this.widgetHost.viewContainerRef.clear();
        }
        this.ngOnInit();
      }
    }

    if (changes.switch && !changes.switch.isFirstChange()) {
      if (this.getLayout() === 'custom') {
        this.loadComponent();
      } else {
        if (this.widgetHost.viewContainerRef) {
          this.widgetHost.viewContainerRef.clear();
        }
      }
    }
  }
Example #18
Source File: example-container.component.ts    From halstack-angular with Apache License 2.0 6 votes vote down vote up
public ngOnChanges(changes: SimpleChanges): void {
    const inputs = Object.keys(changes).reduce((result, item) => {
      result[item] = changes[item].currentValue;
      return result;
    }, {});

    this.defaultInputs.next({ ...this.defaultInputs.getValue(), ...inputs });
    this.className = `${this.getDynamicStyle(this.defaultInputs.getValue())}`;
  }
Example #19
Source File: fy-currency.component.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    if (
      this.fg &&
      changes.txnDt &&
      changes.txnDt.previousValue &&
      changes.txnDt.currentValue &&
      !isEqual(changes.txnDt.previousValue, changes.txnDt.currentValue)
    ) {
      from(this.currencyService.getExchangeRate(this.fg.value.currency, this.homeCurrency, this.txnDt || new Date()))
        .pipe()
        .subscribe((newExchangeRate) => {
          this.exchangeRate = newExchangeRate;
          if (this.innerValue.orig_amount && this.innerValue.orig_currency !== this.homeCurrency) {
            this.innerValue.amount = this.innerValue.orig_amount * this.exchangeRate;
            this.fg.value.amount = this.innerValue.orig_amount;
            this.fg.value.homeCurrencyAmount = this.innerValue.amount;
          }
        });
    }
  }
Example #20
Source File: autocomplete.component.ts    From geonetwork-ui with GNU General Public License v2.0 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    const { value } = changes
    if (value) {
      const previousTextValue = this.displayWithFn(value.previousValue)
      const currentTextValue = this.displayWithFn(value.currentValue)
      if (previousTextValue !== currentTextValue) {
        this.updateInputValue(value.currentValue)
      }
    }
  }
Example #21
Source File: account-struct.component.ts    From assetMG with Apache License 2.0 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    // Get new adgroups if active account has changed
    if (
      changes.account?.currentValue?.id != changes.account?.previousValue?.id
    ) {
      this.addAdGroupsToTable();
    }
    if (changes.uploadMode) {
      this.displayedColumns$.next(this.getDisplayedColumns());
      this.pageSizeOptions = [5, 25, 50];
      this._changeDetectorRef.detectChanges();
    }
  }
Example #22
Source File: ngx-chess-board.component.ts    From ngx-chess-board with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
        if (
            (changes.lightDisabled &&
                this.lightDisabled &&
                this.engineFacade.board.currentWhitePlayer) ||
            (changes.darkDisabled &&
                this.darkDisabled &&
                !this.engineFacade.board.currentWhitePlayer)
        ) {
            this.engineFacade.board.possibleCaptures = [];
            this.engineFacade.board.possibleMoves = [];
        }
    }
Example #23
Source File: color-canvas.component.ts    From angular-material-components with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    if (changes.color && changes.color.currentValue) {
      this.updateForm(changes.color.currentValue);
      if (this._resetBaseColor) {
        this._baseColor = changes.color.currentValue;
      }

      this._resetBaseColor = true;

      if (!changes.color.firstChange) {
        this.draw();
      }
    }
  }
Example #24
Source File: calendar.ts    From ngx-mat-datetime-picker with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges) {
    const change =
      changes['minDate'] || changes['maxDate'] || changes['dateFilter'];

    if (change && !change.firstChange) {
      const view = this._getCurrentViewComponent();

      if (view) {
        // We need to `detectChanges` manually here, because the `minDate`, `maxDate` etc. are
        // passed down to the view via data bindings which won't be up-to-date when we call `_init`.
        this._changeDetectorRef.detectChanges();
        view._init();
      }
    }

    this.stateChanges.next();
  }
Example #25
Source File: tree-table.component.ts    From ng-ant-admin with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    if (changes['cashArray'] && !changes['cashArray'].firstChange) {
      this.checkedCashArrayFromComment = [...changes['cashArray'].currentValue];
      fnGetFlattenTreeDataByMap(this.mapOfExpandedData).forEach(row => {
        // 判断缓存中是否有该值,有的话设置成true
        const index = this.checkedCashArrayFromComment.findIndex(item => item.id === row.id);
        this.setIsCheckFn(row, index !== -1);
      })
      this.refreshStatus();
    }
  }
Example #26
Source File: highlight.directive.ts    From angular-text-search-highlight with MIT License 6 votes vote down vote up
ngOnChanges(changes: SimpleChanges): void {
    if (!this.content) {
      return;
    }

    if (this.setTitle) {
      this.renderer.setProperty(
        this.el.nativeElement,
        'title',
        this.content
      );
    }

    if (!this.searchedWord || !this.searchedWord.length || !this.classToApply) {
      this.renderer.setProperty(this.el.nativeElement, 'innerHTML', this.content);
      return;
    }

    this.renderer.setProperty(
      this.el.nativeElement,
      'innerHTML',
      this.getFormattedText()
    );
  }