Artem Svirskyi
Artem Svirskyi

Reputation: 7849

Ionic radio group on new page component

I'm new to ionic and angular and I want to create a custom element directive, like:

<radio-group 
    value="'a'" 
    values="{{['a', 'b', 'c']}}" 
    on-value-change="onChange()" 
    radio-group-name="'Values'"
></radio-group>

function onChange(newValue){}

so it's pretty similar to example on ionic site, but I need it to generate link

<a href="#/radio-group-page">Values</a>

by clicking it we are going on a new page with values list and 'Values' title. When we select new item, on-value-change event fires.

Is it possible? I don't know how to bind this functionality between pages.

I dont want to create new template and controller for each radio-group.

Upvotes: 0

Views: 82

Answers (1)

Smit
Smit

Reputation: 2148

According to me for a newbie best would be to set a factory!

myApp.factory('Data', function(){
        var data =
            {
                valueSelected: ''
            };

        return {
            getValue: function () {
                return data.valueSelected;
            },
            setValue: function (selected) {
                data.valueSelected = selected;
            }
        };
    });

In your radio controller:

myApp.controller('RadioCtrl', function( $scope, Data ){
    Data.setValue($scope.radioValue);
});

In your main Controller

myApp.controller('mainCtrl', function( $scope, Data ){
    var valueReceived = Data.getValue();
    //do what you want with your data!
});

Upvotes: 2

Related Questions