【发布时间】:2014-10-17 20:41:13
【问题描述】:
我正在尝试为带有值的无线电输入创建指令。这些值将从指令传递。当单选按钮更改时,我还想更新控制器中的值。这是我想出的...
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)
谁能看到我错过了什么?
【问题讨论】:
-
周末还没休息 :-) 我会告诉你的
标签: angularjs angularjs-directive angularjs-scope angular-directive