Hi Martin,

You can use ng-model inside the directive as follows:

Directive: 
myApp.directive('radioChoice', function(){
    return{
    restrict : 'AE',
    scope : {
        model : '=',
        list : '='
    },
    template : '<p ng-repeat="text in list" style="float:left;"><input 
type="radio"'
        + 'ng-model="$parent.model" value="{{text}}">{{text}}</p>'
    };
});

HTML:
<div radio-choice list="radioList" model="radio"></div>

controller:
$scope.radioList = ['Option1','Option2','Option2'];

The trick here is using $parent.model, so that the selected value is stored 
in the variable "radio".


On Tuesday, December 11, 2012 8:36:31 AM UTC-6, Martin Kuhn wrote:
>
> Hi,
>
> I would like to create a directive for a radio group. It uses ng-repeat 
> and input elements of type="radio".
>
> But I have no idea how to define ng-model for this directive so that 2-way 
> databinding is working. 
>
> Here is my fiddle: http://jsfiddle.net/maku/xVKcr/ (it shows a code 
> fragment with directive and without)
>
> Can anybody of you give me a hint?
>
> TIA
> Martin
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to