値を持つラジオ入力のディレクティブを作成しようとしています。これらの値はディレクティブから渡されます。また、ラジオボタンが変更されたときにコントローラーの値を更新したいと考えています。これが私が思いついたものです...
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 )
誰かが私が欠けているものを見ることができますか?