AngularJS ng-repeat单选按钮列表:选定的单选返回未定义的值

鸢尾花

我发现很多人有相同的问题,但给出的答案对我不起作用。

这是我的代码:

<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}}"/>&nbsp;
      <img class="images" ng-src="{{image.url}}" width="50" height="50"/>&nbsp;
      <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,我尝试了所有在网上找到的答案,但就我而言,始终是未定义的。任何人都知道如何获取所选单选按钮的值?

鸢尾花

发布后立即找到答案,也许可以对某人有所帮助。仅仅做$ parent.img还是不够的,因为那只涉及到子控制器的范围,但是我不得不做:ng-model =“ $ parent。$ parent.img”转到父控制器。 。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

AngularJS - ng-repeat 多个单选按钮组,数组的值

使用ng-repeat AngularJS中的ICheck单选按钮获取选定的索引

未选中嵌套ng-repeat中的Angularjs单选按钮

AngularJS ng-repeat传递的索引未定义

选中的单选按钮在ng-model中返回未定义

在ng-repeat中获取元素的比例在Angularjs中返回未定义

Angularjs 返回错误无法在 ng-repeat 中设置未定义的属性“subcomment_like”

AngularJS 1.5.8-2个级别的ng-repeat中的单选按钮列表无法正常工作

如何使用ng-repeat在angularjs中动态禁用单选按钮

默认情况下不选中AngularJS ng-repeat单选按钮

AngularJS单选按钮不会从ng-model对象值中选择适当的按钮

将ng-value用于单选按钮(angularjs)

将ng-form与ng-repeat一起使用时,已连接AngularJs单选按钮

如果从外部ng-repeat $ scope进行的更新也未定义,则ng-repeat中的AngularJS ng-model $ scope是未定义的

ng-repeat + ng-change-AngularJs

ng-checked和ng-change单选按钮无法一起使用-angularjs

AngularJS-ng-repeat中的表格在控制器中未定义

AngularJS-ng-repeat,更新尚未定义的模型对象索引

AngularJS-筛选ng-repeat中未定义的属性?

带有点的 Angularjs 范围变量在 ng-repeat 中显示未定义

从ng-repeat Angularjs下拉列表中的选定选项更新输入值

AngularJS“垂直” ng-repeat

AngularJs。ng-repeat问题

AngularJS IF ELSE 与 ng-repeat

单选按钮值返回未定义

单选按钮返回“未定义”值

ng-repeat 值未定义

带有ng-repeat的角度单选按钮列表

自动编号Angularjs ng-repeat列表