如何优化NG-开关 [英] How to optimize ng-switch

查看:102
本文介绍了如何优化NG-开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采用了棱角分明的NG-交换机来构建这样的表单域

I'm using angular's ng-switch to build form's fields like this

<div ng-switch="vm.myField">
    <my-input-type1 ng-switch-when="type1"></my-input-type1>
    <my-input-type2 ng-switch-when="type2"></my-input-type2>
    <my-input-type3 ng-switch-when="type3"></my-input-type3>
    <my-input-type4 ng-switch-when="type4"></my-input-type4>
    <my-input-type5 ng-switch-when="type5"></my-input-type5>
    <my-input-type6 ng-switch-when="type6"></my-input-type6>
    <my-input-type7 ng-switch-when="type7"></my-input-type7>
    <my-input-type8 ng-switch-when="type8"></my-input-type8>
</div>

由于性能这不是很好的解决方案(在进入查看与其brwser被暂停了一段时间)。
如果没有 NG-开关都是相当好的。

如何优化呢? NG-如果有相同的prefomrance问题。

How can I optimize it? ng-if has the same prefomrance issue.

推荐答案

我想我找到了解决办法。
欧洲工商管理学院的 NG-开关我使用
&LT; NG-包括SRC =/我字段/指令/+ vm.myField +'HTML'。&GT;&LT; / NG-包括&GT; 适当HTML code。
对于现在的工作很好,但一定要考多一点。

I think I found a solution. Insead of ng-switch I'm using <ng-include src="'/my-fields/directives/'+vm.myField+'.html'"></ng-include> with proper html code. For now works good but have to test a bit more.

编辑:现在是多少,更快

now it is much, much faster

这篇关于如何优化NG-开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆