0

値を持つラジオ入力のディレクティブを作成しようとしています。これらの値はディレクティブから渡されます。また、ラジオボタンが変更されたときにコントローラーの値を更新したいと考えています。これが私が思いついたものです...

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.selected = 1;
  $scope.values = [
    1,2,3,4
    ];
  $scope.update=function(){
    console.log("the value is "+ $scope.selected)
  }
})
.directive('jgRadio', function() {
    return {
      restrict:"E",
      scope:{
        values:"=",
        selected:"=",
        update:"&"
      },
      template: '<input ng-repeat="item in values" type="radio" value="{{item}}" ng-model="$parent.selected" ng-change="update()"></input>'
    };
  });

しかし、コンソールログは以前に選択されたものを出力します ( plunker )

誰かが私が欠けているものを見ることができますか?

4

2 に答える 2

0

私の解決策: http://plnkr.co/edit/FcivQTotZAyjh5EvFNRr

  $scope.update=function(){
    $timeout(function(){
      console.log("the value is "+ $scope.selected);
    })
  }
于 2014-10-17T21:07:12.507 に答える