微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误TypeError:无法读取null的属性“ 3”

如何解决错误TypeError:无法读取null的属性“ 3”

我正在使用角度为9的owlCarousel来显示视频。加载时返回错误#tomato_DIV { background-color: tomato; padding: 0px 0px 5px 0px; width: 310px; border-radius: 5px; } #textarea_main { Box-sizing: border-Box; margin: 5px 5px 0px 5px; padding: 2px; /* note: bottom margin is 0 to make flush with yellow div */ width: calc(100% - 10px); height: 75px; resize: none; outline: none; border: 1px solid #737d96; border-radius: 3px; } #floating_Note_DIV { margin: 0px 0px 5px 0px; padding: 0px 2px 0px 0px; position: relative; position: absolute; right: 0; bottom: 100%; width: 70px; height: 11px; font-size: 8px; font-style: normal; font-weight: bold; color: black; text-align: right; border: 1px solid #737d96; } #yellow_DIV { margin: 0px 5px 5px 5px; /* note: top margin is 0 to make flush with textarea */ border: 1px solid grey; position: relative; border-radius: 3px; width: calc(100% -10px); height: 30px; background-color: #fdffb6; }

这是我的html页面,用于加载OwlCarousel

<div id='tomato_DIV'>
  <textarea id="textarea_main" cols="40" rows="3" maxlength="300">
  </textarea>

  <div id="yellow_DIV">
    <div id="floating_Note_DIV">Your Thoughts!!</div>
  </div>
</div>

打字稿文件

Cannot read property '3' of null

enter image description here

感谢您的帮助。

解决方法

在我看来,您的轮播会在开始投放之前进行初始化。为此,您可以对属性使用*ngIf,当属性为true时,它将被初始化。

<div *ngIf="somePropToBeTruthy" class="owl-carousel owl-theme">
   ...
</div>
,

您可以像这样在角度中使用轮播,而不是使用jquery使用angular的功能

<owl-carousel-o [options]="customOptions">
<ng-template carouselSlide *ngFor="let data of sliderImages">
    <div class="slider-item">
        <img [src]="data.image" alt="data.image">
    </div>
</ng-template>
customOptions: OwlOptions = {
    loop: true,mouseDrag: true,touchDrag: true,pullDrag: true,autoplay: true,rtl: true,dots: false,navSpeed: 700,items: 1,responsive: {
        0: {
            items: 1
        },},navText: ['',''],nav: true,autoHeight:true
};


 sliderImages = [
    {
       'image':'abc.png'
    },{
       'image':'abc1.png'
    }]
,

我认为jquery已正确集成。然后,您应按以下方式将代码放入ValueError: Input contains NaN内(ngAfterViewInit替换了文档的ready事件),

ngAfterViewInit

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。