Angularjs 设置ng repeat(角度js)内部无线电的默认值

Angularjs 设置ng repeat(角度js)内部无线电的默认值,angularjs,Angularjs,如果收音机的默认值是对象而不是字符串,如何设置该值 编辑: 为了让事情更清楚,我更新了他的小提琴: 看看小提琴: 在浏览器控制台中检查live html,您将看到,occonnection是一个对象,radio的值变为:{“id”:1,“sId”:“模拟”}。您可能希望使用occonnection.id作为值 ng repeat中的另一个问题是,需要通过将ng model设置为$parent.variableName来解决ng model的范围继承问题 您的oConnectionTmpView

如果收音机的默认值是对象而不是字符串,如何设置该值

编辑:

为了让事情更清楚,我更新了他的小提琴: 看看小提琴:


在浏览器控制台中检查live html,您将看到,
occonnection
是一个
对象
,radio的值变为:
{“id”:1,“sId”:“模拟”}
。您可能希望使用
occonnection.id
作为值

ng repeat
中的另一个问题是,需要通过将
ng model
设置为
$parent.variableName
来解决
ng model
的范围继承问题

您的
oConnectionTmpView
对我来说没有任何意义,因此为了简化,我将其删除:

HTML:

<div ng-show="!oConnection.aOptions" ng-repeat="oConnection in oFormOptions.aStationaryConnections">
  <label>
       <input type="radio"  
              name="connection" 
              ng-model="$parent.oConfigTerminal" 
               value="{{oConnection.id}}"
         />
           {{oConnection.sId}}
     </label>
 </div>

演示:

对不起。JSFIDLE一直在和我胡闹。。。。我更新了你的小提琴,向你展示了我想要达到的目标:你是个天才!如果我将$scope.oConfigTerminal设置为1而不是0,则它可以工作=)下面是另一种方法。。。观察无线电模型并使用其值设置对象
app = angular.module('app', []);

app.controller('controller', function ($scope) {
$scope.oFormOptions = {};
$scope.oConfigTerminal=0;
$scope.oFormOptions.aStationaryConnections = [{
    id: 1,
    sId: "analog"
}, {
    id: 2,
    sId: "isdn"

}, {
    id: 3,
    sId: "dsl"
}];

// !!! Trying to set the default checked/selected value !!!
$scope.oConfigTerminal = $scope.oFormOptions.aStationaryConnections[0];
});
<div ng-show="!oConnection.aOptions" ng-repeat="oConnection in oFormOptions.aStationaryConnections">
  <label>
       <input type="radio"  
              name="connection" 
              ng-model="$parent.oConfigTerminal" 
               value="{{oConnection.id}}"
         />
           {{oConnection.sId}}
     </label>
 </div>
app = angular.module('app', []);

app.controller('controller', function ($scope) {
    $scope.oFormOptions = {};
    $scope.oConfigTerminal = 0;
    $scope.oFormOptions.aStationaryConnections = [{
        id: 1,
        sId: "analog"
    }, {
        id: 2,
        sId: "isdn"

    }, {
        id: 3,
        sId: "dsl"
    }];
}