templateRef.createEmbeddedView is not a function

背景:在使用Swper封装一个组件时,碰到这样一种常见,使用*ngIf判断数据类型,如果为数组就去循环dom,如果不是就直接使用ng-template的ngTemplateOutlet去接收,但是碰到这样一个错误。

templateRef.createEmbeddedView is not a function

 刚开始的写法

   <div class="swiper-wrapper">
      <ng-template *ngIf="isArrayItems; else itemsDom">
        <div class="swiper-slide" *ngFor="let item of items">
          <ng-template [ngTemplateOutlet]="item.item"></ng-template>
        </div>
      </ng-template>
      <ng-template #itemsDom [ngTemplateOutlet]="items"></ng-template>
    </div>

 发现主要是由于

<ng-template #itemsDom [ngTemplateOutlet]="items"></ng-template> 这句的写法导致的,itemsDom直接使用了ngTemplateOutlet

需要在外层在包一层

  <ng-template #itemsDom>
     <ng-template  [ngTemplateOutlet]="items"></ng-template>
    </ng-template>

修改后的写法

<div class="swiper-wrapper" *ngIf="isArrayItems; else itemsDom">
        <div class="swiper-slide" *ngFor="let item of items">
          <ng-template [ngTemplateOutlet]="item.item"></ng-template>
        </div>
    </div>
    <ng-template #itemsDom>
      <div class="swiper-wrapper">
        <ng-template  [ngTemplateOutlet]="items"></ng-template>
      </div>
    </ng-template>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]: 当出现"Uncaught TypeError: xxx.split is not a function"错误提示时,这意味着变量xxx不是一个字符串类型的值。解决方法是将变量转换为字符串类型。你可以使用toString()方法将变量转换为字符串类型。例如,将变量xxx转换为字符串类型的代码是xxx.toString()。\[1\] 问题: 当出现"this.dataww.split is not a function"错误时,该如何解决? 回答: 当出现"this.dataww.split is not a function"错误时,这意味着this.dataww不是一个字符串类型的值。你可以使用toString()方法将this.dataww转换为字符串类型,例如this.dataww.toString()。这样就可以解决这个错误了。 #### 引用[.reference_title] - *1* [JS解决Uncaught TypeError: xxx.split is not a function报错](https://blog.csdn.net/paradoxaaa_/article/details/127888749)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [node.js使用ini模块读取ini文件报错TypeError: str.split is not a function](https://blog.csdn.net/cnds123321/article/details/121727100)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值