我有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 log和commit.