将索引附加到对象引用

时间:2015-11-12 16:04:24

标签: javascript angularjs

我如何改变这一点:

ng-messages="createCourseForm.quizItemMultipleChoiceAnswer+$index.$error"

成:

ng-messages="createCourseForm.quizItemMultipleChoiceAnswer0.$error"

1 个答案:

答案 0 :(得分:1)

It looks like you are trying to access a specifically named property from your form. If you need the property name to be variable, you can use javascript's bracket notation来访问属性。然后,您可以传入任何字符串并访问该属性。

ng-messages="createCourseForm['quizItemMultipleChoiceAnswer' + $index].$error"