的别名所以,如果我有这样的HTML:变量赋值在AngularJS
<ul>
<li ng-repeat="person in course.people">
<div>
<span bg-bind="schools[schools.currentSchool][person.id].gradeAverage"></span>
</div>
<div>
<span bg-bind="schools[schools.currentSchool][person.id].bestGrade"></span>
</div>
<div>
<span bg-bind="schools[schools.currentSchool][person.id].worstGrade"></span>
</div>
<div>
<span bg-bind="schools[schools.currentSchool][person.id].numberOfClasses"></span>
</div>
<div>
<span bg-bind="schools[schools.currentSchool][person.id].year"></span>
</div>
<div>
<span bg-bind="schools[schools.currentSchool][person.id].timesFlunked"></span>
</div>
</li>
</ul>
我需要访问schools[schools.currentSchool][person.id]
多次,这使得代码看起来很凌乱了一段时间后。有什么方法可以将ng-alias="x=schools[schools.currentSchool][person.id]"
之类的东西放在某处吗?所以我可以在需要的地方使用x.gradeAverage
。或者其他一些让HTML看起来不那么混乱的方法?
顺便说一句,这个例子的HTML完全是任意的,我只是做了一些事情,但我希望你明白我在问什么。
在你的'ngRepeat' - NG-'现在重复范围内的init =“x = schools [schools.currentSchool] [person.id]”' - 'x“将引用该路径。 – tymeJV
@tymeJV:如果'DOMS [schools.currentSchool] [person.id]'在没有反映到DOM中的范围内发生变化,那么这会使变量static = = if。 –