I am trying to pass some simple boolean and string values with my promise. Here is the method renedering the a modal within the view:
$scope.openHjelpModal = function (field) {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'app/produkt/ny/views/hjelpModal.html',
controller: 'hjelpModalController',
});
modalInstance.result.then(function (field) {
var kategori = '';
var pakning = false;
var epd = false;
var lansering = false;
switch (field) {
case 'p':
console.log('pakningsoppbyggning rendering');
pakning = true;
epd = false;
lansering = false;
kategori = 'pakningsoppbyggning';
break;
case 'e':
console.log('epd-kategori rendering');
pakning = false;
epd = true;
lansering = false;
kategori = 'EPD-kategori';
break;
case 'l':
console.log('lansering rendereing');
pakning = false;
epd = false;
lansering = true;
kategori = 'lansering';
break;
}
}, function () {
//logService.info('Modal dismissed at: ' + new Date());
});
};
I need to pass the booleans and string to the modal somehow. I know the recomended approach would be a service, but I haven't been able to follow any of the solutions provided here so far.
Here is how I will be using the variables in the modal(html file):
<h4>Hjelp for: {{kategori}} </h4>
<div ng-if="lansering">
<p> kommer fra lansering</p>
</div>
<div ng-if="epd">
<p> kommer fra epd</p>
</div>
<div ng-if="pakning">
<p> kommer fra pakning</p>
</div>
<div class="modal-footer">
<button class="btn btn-green pull-left" type="button" ng-click="lukk();">Lukk</button>
</div>
running console log from the hjelpModalController returns undefined, this is with the changes provided in the answers:
$scope.openHjelpModal = function (field) {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'app/produkt/ny/views/hjelpModal.html',
controller: 'hjelpModalController',
resolve: function () {
return field;
}
});
console.log(field); // works here
}
And from the hjelpModalController:
angular.module('app').controller('hjelpModalController', hjelpModalController);
hjelpModalController.$inject = ['$scope','$uibModalInstance'];
function hjelpModalController($scope, $uibModalInstance, field) {
console.log(field); // returns undefined
}
UPDATE:
Here is the latest progress i have made:
controller passing the variable:
$scope.openHjelpModal = function (field) {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'app/produkt/ny/views/hjelpModal.html',
controller: 'hjelpModalController',
resolve: {
selectedHelpModal: function () {
console.log(field); // correct output
return field;
}
}
});
modalInstance.result.then(function () {
console.log('or here');
console.log(field); // correct output
});
}
controller recieving the variable:
angular.module('app').controller('hjelpModalController', hjelpModalController);
hjelpModalController.$inject = ['$scope','$uibModalInstance'];
function hjelpModalController($scope, $uibModalInstance, field) {
console.log('hjelp modal controler is running');
console.log(field); // undefined
}