指令内的角度形式,具有隔离范围

Angular form inside directive with isolated scope

本文关键字:隔离 范围 指令      更新时间:2023-09-26

我有这样的表格

<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 类和指令范围内)。我认为数据绑定存在一些问题...

关于此行为的可能错误的任何建议?

您的单选按钮似乎没有值。

向单选按钮添加一些值,然后重试。例如

<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>