我正在尝试为带有值的无线电输入创建指令。这些值将从指令传递。当单选按钮更改时,我还想更新控制器中的值。这是我想出的...
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)
有人可以看到我缺少什么吗?