question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing Instant Search into Angular 2 CLI

See original GitHub issue

Do you want to request a feature or report a bug? BUG

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

11reactions
codediodeiocommented, Jul 17, 2017
3reactions
iam4xcommented, Oct 18, 2017

@darthsitthiander I’ve looked to your repo, you did not take the same approach as the other components you implemented. You need to follow this kind of pattern without references to jQuery in your DOM operations.

And here is a correct pagination component for AngularJS:

import { Component, OnInit } from '@angular/core';
import { InstantSearchService } from '../../services/instantsearch.service';
import { connectPagination } from 'instantsearch.js/connectors';

@Component({
  selector: 'app-pagination',
  template: `
    <div class="is-pagination-root">
      <ul>
        <li
          *ngFor="let page of pages"
          (click)="state.refine(page)"
          [ngClass]="{'active': page === state.currentRefinement}"
        >
          {{page + 1}}
        </li>
      </ul>
    </div>
  `,
  styles: [`
    ul, li {
      margin: 0;
      padding: 0;
      display: inline-block;
    }

    li {
      cursor: pointer;
      margin-right: 5px;
    }

    li.active {
      color: red;
      font-weight: bold;
    }
  `]
})
export class PaginationComponent implements OnInit {
  state: {
    currentRefinement: number,
    nbPages: number,
    refine: Function
  } = {
    currentRefinement: 0,
    nbPages: 0,
    refine: () => {}
  };

  constructor(private instantSearchService: InstantSearchService) {}

  get pages(): number[] {

    return Array
      .apply(null, {length: this.state.nbPages})
      .map(Number.call, Number)
  }

  ngOnInit() {
    const widget = connectPagination(this.updateState);
    this.instantSearchService.search.addWidget(widget({ maxPages: 10 }));
  }

  updateState = (state, isFirstRendering) => {
    if (isFirstRendering) {
      return Promise.resolve(null).then(() => {
        this.state = state;
      })
    }

    this.state = state;
  }
}

Anyway, like @Haroenv said we are planning a real angular-instantsearch library to simplify the usage 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Instant Search for Angular 2 CLI based project - Open Q&A
I believe is the right way to import instantsearch in your code. It seems you cannot yet use the import syntax with instantsearch.js....
Read more >
Integrating Algolia InstantSearch with Angular - DigitalOcean
First, add the angular-instantsearch package to your Angular project: ; Next, in your app module or a feature module, import the NgAisModule and ......
Read more >
2 - Stack Overflow
1 Answer 1 ; exports = { // The packages that are configured by this project config. packages ; "angular-instantsearch": { // A...
Read more >
Frequently-used modules - Angular
When you use these Angular modules, import them in AppModule , or your feature module as appropriate, and list them in the @NgModule...
Read more >
Algolia Instantsearch.js infused with Angular 4 | by Zev | Medium
Firstly we have to install Angular CLI for our project ... environments/environment';import * as instantsearch from 'instantsearch.js' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found