javascript – 使用ng-include的Angular JS ng-switch?

前端之家收集整理的这篇文章主要介绍了javascript – 使用ng-include的Angular JS ng-switch?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有3个不同的代码片段,我想根据选择菜单中的选择进行交换.

它是有效的,如果我包含内联代码,但当我尝试使用ng-includes这样的时候,我得到一个Angular错误并且应用程序失败:

<div ng-switch on="pFilter">
      <div ng-include="'includes/parcel_details_incoming.html'" ng-switch-when="Incoming Parcels"></div>
      <div ng-include="'includes/parcel_details_forward.html'" ng-switch-when="Exception Parcels"></div>
      <div ng-include="'includes/parcel_details_exception.html'" ng-switch-default></div>
      </div>

我在这做错了什么? ng-switch不适用于ng-includes吗?

解决方法

原因是指令ng-include和ng-switch-x都使用了transclusion,你在同一个元素上指定它们并且不允许.将nginclude移动到ng-switch元素的子节点.
<div ng-switch on="pFilter">
      <div  ng-switch-when="Incoming Parcels"><div ng-include="'includes/parcel_details_incoming.html'"></div></div>
      <div  ng-switch-when="Exception Parcels"><div ng-include="'includes/parcel_details_forward.html'"></div></div>
      <div  ng-switch-default><div ng-include="'includes/parcel_details_exception.html'"></div></div>
   </div>

这曾经工作到角度1.x版本,但复合转换将导致启动1.2.x版本角度的多重错误.看看change logcommit.

原文链接:https://www.f2er.com/js/150411.html

猜你在找的JavaScript相关文章