【发布时间】:2014-04-11 07:38:03
【问题描述】:
我发现很多人都有同样的问题,但给出的答案对我不起作用。
这是我的代码:
<div ng-controller="addEventController">
//other form input fields that will be sent when clicking the button
<div ng-controller="imgListCtrl">
<input ng-repeat-start="image in images" name = "selectImage" type="radio" ng-
model="img" ng-value="{{image.imageid}}"/>
<img class="images" ng-src="{{image.url}}" width="50" height="50"/>
<br ng-if="($index+1) % 10 == 0"/><br ng-if="($index+1) % 10 == 0"/>
<span ng-repeat-end></span>
</div>
<button class="btn-default" ng-click="saveEvent()">Opslaan</button>
</div>
这是“addEventController”的子控制器,在父控制器中,我尝试像这样访问选定的单选按钮值:
myAppProfile.controller('addEventController', function($scope,$location, $http) {
$scope.saveEvent = function() {
$http({
method: 'POST',
url: 'eventController.php',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: {
'begin': $scope.begin + " " + $scope.btijd,
'einde': $scope.einde + " " + $scope.etijd,
'beschrijving': $scope.beschrijving,
'img': $scope.img
}
}).
success(function(data, status) {
if(data == "1"){
$location.path("/agenda");
}else{
$scope.errormsg = data;
}
}).
error(function(data, status) {
$scope.errormsg = data;
});
}
});
$scope.img => 总是返回“未定义”。
我发现您必须将 ng-model 对象重命名为 $parent.img 或者您必须将其命名为 images.img,我已经尝试了我在网上找到的所有答案,但就我而言,始终未定义。任何人都知道如何获取所选单选按钮的值?
【问题讨论】:
标签: angularjs radio-button undefined angularjs-ng-repeat