How to get an element and set value inside a modal still closed?

Clicking on an external button i need to set a modal’s internal element value. Both elements are inside different section, so they have different controllers, i need a way to pass the button value from mainCtrl to modalCtrl.

<div id="external-element" ng-controller="mainCtrl">
    <button ng-click="getValue($event)" data-value="1">Get this value</button>

<script id="modal.html" type="text/ng-template">
    <div id="modal-section" class="modal" ng-controller="modalCtrl">
        <p class="waiting-for-button-value"></p>

A tutorial said that i can do it by creating a service:

	var service = {}; = false;
	service.sendData = function(data){ = data;
	service.getData = function(){
	return service;

So inside my controllers:

app.controller('mainCtrl', function($scope, dataShare, $ionicModal){
    $scope.getValue = function(event){
        var myValue = $('value');

app.controller('modalCtrl', function($scope, dataShare){
        var text =  dataShare.getData();

I need to do set my value when the modal is closed because the link with the function setValue() is in my main page, but actually this doesn’t work.

Can someone help me please?