我有以下HTML,在满足ng-show
条件时显示错误消息。但是,无论是否显示错误消息,都会发生ng-init
分配。
<div ng-show="peopleworksForm.submitted && formData['DisclosureQuestion'+($index+1)+'Answer'] == 'true' && formData['DisclosureQuestion'+($index+1)+'OptionalAnswer'] == undefined"
ng-init="$parent.answerValFailed = true">
invalid value
</div>
我想要的是仅在满足ng-init
条件后才在ng-show
内进行操作。有没有简单的方法呢?
答案 0 :(得分:0)
使用ng-if及其内部使用ng-init:)
<div class="pw-form-inline-error" ng-if="peopleworksForm.submited && formData['DisclosureQuestion'+($index+1)+'Answer'] == 'true' && formData['DisclosureQuestion'+($index+1)+'OptionalAnswer'] == undefined">
<span ng-init="$parent.answerValFailed = true">
invalid value
</span>
</div>
希望有所帮助:)