我有一个这样的表格
<ng-form name="investorQuestionaireForm" ng-show="user && user.investorType">
<input
type="radio"
required
name="recesso"
ng-model="investorQuestionaire.recesso"
ng-change="investorQuestionaireValidation('recesso', investorQuestionaireForm)"/>
<input
type="radio"
required
name="recesso"
ng-model="investorQuestionaire.recesso"
ng-change="investorQuestionaireValidation('recesso', investorQuestionaireForm)"/>
</ng-form>
此表单位于指令内:
angular.module('crowdcoreApp').directive('investorForm',function(){
templateUrl: 'views/template/equity_investor_form.html',
restrict: 'E',
scope: {
project: '=project'
},
});
我面临的问题是,当我单击单选按钮时,investorQuestionaire.recesso
的值未更新,ng-change
函数未更新触发,并且最重要的是 radio
按钮,仍然是原始的(在 html 类和指令范围内)。我认为数据绑定(bind)存在一些问题...
对这种行为可能出现的错误有什么建议吗?
最佳答案
您的单选按钮似乎没有值。
向单选按钮添加一些值,然后重试。例如
<ng-form name="investorQuestionaireForm" ng-show="user && user.investorType">
<input
type="radio"
required
value="option1"
name="recesso"
ng-model="investorQuestionaire.recesso"
ng-change="investorQuestionaireValidation('recesso', investorQuestionaireForm)"/>
<input
type="radio"
required
value="option2"
name="recesso"
ng-model="investorQuestionaire.recesso"
ng-change="investorQuestionaireValidation('recesso', investorQuestionaireForm)"/>
</ng-form>
关于javascript - 具有隔离范围的指令内的 Angular 形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27293708/