javascript - Angular遍历Radio选项,如何设置某个选项为默认选中状态?
PHPz
PHPz 2017-04-11 12:25:41
[JavaScript讨论组]
  • talking ischeap,show me the code(不要逼逼,直接看代码)




    
        
        Angular Radio测试
        
    

    
        

  • 运行效果


感谢@crazy4x 的评论,JS代码改成下面这样就可以了!

PHPz
PHPz

学习是最好的投资!

全部回复(2)
高洛峰
$scope.viewModel={
    orgType = $scope.orgTypes[0]
}
阿神
<script type="text/javascript">
    var testObj = angular.module('testApp',[]);
    testObj.controller("testCtr",function($scope){
        $scope.orgTypes = ['其他','医院','养老院'];
        $scope.viewModel.orgType = $scope.orgTypes[0];
    });
</script>

写了之后,Angular遍历出错了

TypeError: Cannot set property 'orgType' of undefined
    at new <anonymous> (test4NgRadio.html:24)
    at Object.invoke (angular.js:4862)
    at $controllerInit (angular.js:10717)
    at nodeLinkFn (angular.js:9594)
    at compositeLinkFn (angular.js:8903)
    at compositeLinkFn (angular.js:8906)
    at publicLinkFn (angular.js:8768)
    at angular.js:1847
    at Scope.$eval (angular.js:18017)
    at Scope.$apply (angular.js:18117)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号