Angularjs使用输入无线电ngModel设置rootScope

时间:2014-07-11 10:55:48

标签: angularjs radio-button angular-ngmodel rootscope

谁知道为什么它不起作用?

我想在单选按钮上使用ngModel设置$ rootScope值。

这是一个例子jsFiddle

    <form  name="pageTwoForm">
        <h3>General Information > Knowledge About </h3>
        <div>
        <b>User</b>
            <div ng-repeat="option in userOptions">
                <input type="radio" ng-model="knowledgeAboutUser" ng-value="option.id" />{{option.text}}
            </div>

<b>Target Group</b>
            <div ng-repeat="option in targetGroupUserOptions">
                <input type="radio" ng-model="$parent.knowledgeAboutTargetGroup" ng-value="option.id" />
                {{option.text}}
            </div>
    </div>
</form>
    <h3 >{{knowledgeAboutTargetGroup}}</h3>
    <h3 >{{knowledgeAboutUser}}</h3> 

1 个答案:

答案 0 :(得分:3)

我解决了它

    <form  name="pageTwoForm">
        <h3>General Information > Knowledge About </h3>
        <div>
        <b>User</b>
            <div ng-repeat="option in userOptions">
                <input type="radio" ng-model="data.knowledgeAboutUser" ng-value="option.id" />{{option.text}}
            </div>

<b>Target Group</b>
            <div ng-repeat="option in targetGroupUserOptions">
                <input type="radio" ng-model="data.knowledgeAboutTargetGroup" ng-value="option.id" />
                {{option.text}}
            </div>
    </div>
</form>
    <h3 >{{data.knowledgeAboutTargetGroup}}</h3>
    <h3 >{{data.knowledgeAboutUser}}</h3> 

我不知道为什么但如果我使用

它会起作用
  

data.knowledgeAboutUser

不仅

  

knowledgeAboutUser