我的格式为textarea
:
<form name="new_project">
<textarea autofocus="autofocus"ng-model="description" ng-maxlength="10" name="campaign[description]"></textarea>
</form>
我试图显示输入状态,如:
{{new_project.campaign[description].$valid}}
它什么都没有,为什么?
答案 0 :(得分:2)
你应该这样做:
{{new_project['campaign[description]'].$valid}}
原因:
name="campaign[description]"
向表单对象添加一个属性,字面意思为字符串 'campaign[description]'
,并且访问此属性值的唯一方法是将该字符串包装在[]中。
点符号在这里无法工作,因为否则JavaScript解释器会期望在campaign[description]
中访问campaign
提供的属性括号之间[]:在你的情况下是description
的值,我猜它是undefined
。
答案 1 :(得分:0)
试试这个
<form name="new_project">
<textarea autofocus="autofocus"ng-model="description" ng-maxlength="10" name="campaign{{description}}"></textarea>
</form>
和
{{new_project['campaign'+description].$invalid}}
答案 2 :(得分:0)
使用{{new_project.textarea.$valid}}
传递元素以检查有效性