Angular 9-简单幻灯片-错误TypeError:无法读取未定义的属性'nativeElement'

问题描述 投票:0回答:1

角度9中的nativeElement' of undefined出现[ng-simple-slider问题

错误

core.js:5871 ERROR TypeError: Cannot read property 'nativeElement' of undefined
        at SlideshowComponent.setStyles (ng-simple-slideshow.js:517)
        at SlideshowComponent.ngDoCheck (ng-simple-slideshow.js:189)
        at callHook (core.js:3939)
        at callHooks (core.js:3899)
        at executeInitAndCheckHooks (core.js:3840)
        at selectIndexInternal (core.js:9598)
        at Module.ɵɵadvance (core.js:9559)
        at CategoryComponent_Template (category.component.html:16)
        at executeTemplate (core.js:11926)
    at refreshView (core.js:11773)

TEMPLATE

<section class="slider" >
  <slideshow #slideshow id="slideshow" [imageUrls]="imageUrls"  [autoPlay]="true" ></slideshow>
</section>

Component.ts] >>

import { Component, OnInit} from '@angular/core';
import {HttpService} from '../../services/http.service';
import {LoaderService}  from '../../services/loader.service';
import { Router, ActivatedRoute } from '@angular/router';
import {trigger, transition, style, animate, query, stagger} from '@angular/animations';
import { Title } from '@angular/platform-browser';
import { PlatformLocation } from '@angular/common';
import { IImage } from '../../interfaces/IImage';

@Component({
  selector: 'app-slider',
  templateUrl: './slider.component.html',
  styleUrls: ['./slider.component.css'],
})

export class SliderComponent implements OnInit {
  resultdata: any = {}; 
  imageUrls: (string | IImage)[] = [];
  constructor(private HttpService: HttpService ,
              private router: Router, 
              private loader : LoaderService, 
              private titleService: Title,
              ) {
    this.titleService.setTitle('Home | Example');
   }

  ngOnInit() {
    this.HttpService.postdata({'auth_token' : xxxxxx} , 'home').subscribe( result  =>  {
           this.resultdata = result;
           if(this.resultdata.data.banners.length > 0){
              for (var i in this.resultdata.data.banners) {  
                this.imageUrls.push({
                          url : this.resultdata.data.banners[i].image.medium,
                          caption: this.resultdata.data.banners[i].description,
                          title: this.resultdata.data.banners[i].description,
                  });   
              }
           }
          });
  }
}

imageUrls

this.imageUrls = [{
          url : 'https://example.com/image/1.png',
          caption: 'Image 1',
          title: 'Image 1',
  },{
          url : 'https://example.com/image/2.png',
          caption: 'Image 2',
          title: 'Image 2',
  },{
          url : 'https://example.com/image/3.png',
          caption: 'Image 3',
          title: 'Image 3',
  }];   

这里是npm modulehttps://www.npmjs.com/package/ng-simple-slideshow链接>

提前感谢。

angular 9中的ng-simple-slider的未定义问题的nativeElement”错误core.js:5871错误TypeError:无法在SlideshowComponent.setStyles(ng -...

读取未定义的属性“ nativeElement”(ng -...
angular slideshow angular9
1个回答
0
投票
我认为imageUrls需要一个[[String数组,以使幻灯片具有

links

© www.soinside.com 2019 - 2024. All rights reserved.