<a class="clickme" ng-click="vm.open()" >Click ME</a>
In my HTML code, I have a link as given above, clicking on which opens a modal popup. This modal popup is associated with a controller of it's own. So, when this linked is called, I have to pass a value which I obtain through a http request. This is how my controller looks like;
(function() {
angular
.module('myApp.abc', [])
.factory('myService', function($http) {
})
.controller('MyController', function($routeParams, myService, $scope, $uibModal,$http) {
var vm = this;
vm.open = function () {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'path to modal popup',
controller: 'modalPopController',
resolve: {
id: function ()
{
var myid;
var baseUrl = 'services/';
$http.get(baseUrl+ 'get_user_session')
.then(function(response) {
myid = response.id;
return myid;
});
}
}
});
modalInstance.result.then(function (myCroppedImage) {
vm.member.avatar = myCroppedImage;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
});
})();
In this controoler, this is the part where I'm communicationg with a service which returns a value which I'm trying to assign to the variable id. This is that code:
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'path to modal popup',
controller: 'modalPopController',
resolve: {
id: function ()
{
var myid;
var baseUrl = 'services/';
$http.get(baseUrl+ 'get_user_session')
.then(function(response) {
myid = response.id;
return myid;
});
}
}
});
But I'm getting undefined error. What is that so?
UPDATE
If I put a static value like this, it works fine.
resolve: {
id: function () {
return 5;
}
}
My service is returning result as JSON like this:
{"id":"5","name":"John"}