Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carousel some times display no itens #418

Open
brunork26 opened this issue Mar 23, 2018 · 2 comments
Open

Carousel some times display no itens #418

brunork26 opened this issue Mar 23, 2018 · 2 comments

Comments

@brunork26
Copy link

brunork26 commented Mar 23, 2018

So, Im creating a carousel with data from the backend, I populate its array in the constructor function: this is my component.ts:

export class HomeComponent implements OnInit {

  rodeos = [];
  @ViewChild('carousel') carouselElement;
  showInitialized = false;
  actions = new EventEmitter<string>();

  constructor(private elementRef: ElementRef,
              private authService: AuthService,
              private rodeoService: RodeosService) {
  }

  ngOnInit() {
    this.rodeoService.getRodeoList().subscribe(
      data=>{
        this.rodeos = data;
      }
    )
  }

  isLoggedIn(){
    return this.authService.isLoggedIn();
  }
}

My html is like this:

<div #carousel class="carousel" [ngClass]="{ 'initialized': showInitialized }" materialize="carousel">
          <div *ngFor="let rodeo of rodeos" class="carousel-item">
            <!--<div class=''>-->
              <div class="rodeio-card">
                <div class="card">
                  <div class="card-image">
                    <!--Id do rodeio-->
                    <a [routerLink]="['/rodeio/1/info']"><img src="../../../assets/images/banner.png" class="img-responsive"></a>
                  </div>
                  <div class="card-content">
                    <h5><b></b></h5>
                    <div class="row">
                      <div class="col s6">
                        <div class="infos">
                          <img src="../../../assets/images/icon_calendario.png" class="img-responsive">
                          <h4>Data de Início</h4>
                          <h5><b>20/10/2018</b></h5>
                        </div>
                        <div class="infos">
                          <img src="../../../assets/images/ico-location.png" class="img-responsive">
                          <h4>Local</h4>
                          <h5><b>Viamao</b></h5>
                        </div>
                      </div>
                      <div class="col s6">
                        <div class="infos">
                          <img src="../../../assets/images/icon_calendario.png" class="img-responsive">
                          <h4>Data de Encerramento</h4>
                          <h5><b>22/10/2018</b></h5>
                        </div>
                        <div class="infos">
                          <a class="waves-effect waves-light btn btn-inscricao">Inscrição</a>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            <!--</div>-->
          </div>
        </div>

Some times when I reload the page it loads with the property display: none and no transform property, and so nothing appears:

screen shot 2018-03-23 at 14 15 38

And when it appears its like that:

screen shot 2018-03-23 at 14 20 37

This happens in all browsers, some times the cards show, other times it doesn't.

@ghost
Copy link

ghost commented Jun 12, 2018

I have same issue, but i did not find the problem yet :(

@brunork26
Copy link
Author

brunork26 commented Jun 20, 2018

I end up with something like this:

export class HomeComponent implements OnInit {
  public rodeos = [];
  @ViewChild('carousel') carouselElement;
  public showInitialized = false;
  public actions = new EventEmitter<string|MaterializeAction>();

  constructor(private elementRef: ElementRef ) {
    window.setTimeout(() => {
      this.carouselElement.nativeElement.classList.toggle('initialized');
      this.actions.emit('carousel');
    }, 5000);
  }
...
}

But still not the best solution. Setting TimeOut too 2000 sometimes didn't load the data from the api, setting to 5000 takes too long but its working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant