I have a directive like below -
<div data-my-param-control data-save-me="saveMe()"></div>
In directive controller, I bind saveMe() function from controller with isolated scope & like below -
function MyParamControlDirective($filter,
$state,
$stateParams,
$uibModal,
) {
return {
restrict: 'AE',
scope: {
saveMe: '&',
},
templateUrl: 'html/myhtml',
controller: ['$scope', function ($scope) {
$scope.saveMeHandler = function () {
var saveMe = $scope.saveMe();
$uibModal.open({
animation: false,
windowTopClass: '',
templateUrl: 'html/askmyname',
size: 'sm',
resolve: {
saveMe: function () {
return saveMe;
}
},
controller: function (
$scope,
$uibModalInstance,
saveMe,
toastr
)
{
$scope.close = function () {
$uibModalInstance.close();
};
$scope.saveMyName = function() {
$scope.submited = true;
if ($scope.my_name != "undefined" && $scope.my_name != "") {
saveMe();
$scope.close();
} else {
toastr.error('Please enter search name');
}
}
}
});
};
}]
};
}
Everything is working fine till now.
I added a uibModal in directive and open a popup to get a name. the name comes in $scope.my_name variable. Now I want to pass this name in function saveMe(). If I directly pass variable like saveMe($scope.my_name); it shows undefined in controller function. Below is the controller function -
$scope.saveMe = function () {
//logic here to save data
};
Can you guys help me how can I pass my_name from modal to saveMe method. Thanks in advance