Is there a way to pass the data contactName
from the state to the controller using resolves?
.state({
name: 'contact.detail.overlay',
abstract: true,
component: 'overlayContent',
resolve: {
contactName: (originalContact, $rootScope, ContactService) => {
$rootScope.contactName = ContactService.getContactName(originalContact)
return $rootScope.contactName
}
}
})
Although everything seems correct in my state and with the contactName
, I am unable to access it in my overlayContent
controller. Is there a solution to have access to $rootScope.contactName
in the controller?
EDIT: The controller :
class overlayContentComponent {
constructor($state, $interpolate, $scope) {
'ngInject'
this.$scope = $scope
this.$state = $state
this.$interpolate = $interpolate
}
/**
*
* On initialization hook, let's check if an overlay title
* has been defined for the current state.
*/
$onInit() {
const stateData = this.$state.current.data || { title: '' }
this.overlayTitle = angular.isDefined(stateData.title) ? this.$interpolate(stateData.title)() : ''
}
}
export const overlayContentComponent = {
template: require('./overlay-content.html'),
controller: overlayContentComponent
}
I have found that I can access contactName
in my controller using this.$scope.$root.contactName
, but I am looking for an alternative to avoid using $scope.$root
.