html - angularjs中用ng-repeat生成几个radio,怎么设置radio的默认选中项?
巴扎黑
巴扎黑 2017-05-15 17:06:21
0
1
739

我试了一下ng-model,但是没效果,问题在哪?代码如下:
script:

       $scope.allMsgType=[                    
            {id:"11",name:"输入内容"},
            {id:"12",name:"连接h5"},
            {id:"13",name:"无详情"}
        ];
        $scope.msgTypeDefault=$scope.allMsgType[0];

html

       <span ng-repeat="x in allMsgType">
            <label ng-click="events.getMsgTypeData(x.id)">
                <input  name="msgType" type="radio" ng-model="msgTypeDefault">
                <span>{{x.name}}</span>
            </label>
        </span>
巴扎黑
巴扎黑

reply all(1)
我想大声告诉你

You can add an attribute checked to the data model allMsgType to identify whether it is selected by default, and then add the attribute ng-checked to the input to bind the checked attribute of allMsgType, so that you can operate the selected attribute by modifying the data object

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!