任何人都可以帮助我解决在ng-repeat内编译指令时的范围界定问题吗?自定义指令无法在ng-repeat内编译
https://plnkr.co/edit/y6gfpe01x3ya8zZ5QQpt?p=preview
自定义指令input-by-type
可以取代<div>
基于变量类型适当<input>
- 直到ng-repeat
内使用能正常工作。
正如您在plnkr示例中所看到的,该指令按预期工作,直至在ng-repeat
内使用。
如果我手动引用inputs[0]
编译input-by-type
指令,它工作得很好:
<label>
{{ inputs[0].name }}
<div input-by-type="{{ inputs[0].type }}" name="myInputA" ng-model="data.A" ng-required="true"></div>
</label>
然而,那一刻我在ng-repeat
块把这个包,编译失败,一些意想不到的输出:
<label ng-repeat="input in inputs">
{{ input.name }}
<div input-by-type="{{ input.type }}" name="myInput{{ $index }}" ng-model="data[input.id]" ng-required="true"></div>
</label>
预期输出:
实际输出:
我知道的postLink参数但是它并没有醒悟过来了,他们可以根据相位不同。谢谢。 – oodavid