AngularLoader
in package
The AngularLoader loads any JS/CSS/JSON resources required for setting up AngularJS.
This class is returned by 'angularjs.loader' service. Example use:
Civi::service('angularjs.loader')
->addModules('moduleFoo')
->useApp(); // Optional, if Civi's routing is desired (full-page apps only)
Tags
Table of Contents
Constants
- DEFAULT_MODULE_WEIGHT = 200
- The weight to assign to any Angular JS module files.
Properties
- $angular : Manager
- The Angular module manager.
- $crmApp : array<string|int, mixed>|null
- $modules : array<string|int, mixed>
- $modulesAlreadyLoaded : array<string|int, mixed>
- $pageName : string
- $region : string
- The region of the page into which JavaScript will be loaded.
- $res : CRM_Core_Resources
- The resource manager.
Methods
- __construct() : mixed
- AngularLoader constructor.
- addModules() : AngularLoader
- findActiveModules() : array<string|int, mixed>
- Get a list of all Angular modules which should be activated on this page.
- getAngular() : Manager
- getModules() : array<string|int, mixed>
- getPageName() : string
- getRegion() : string
- getRes() : CRM_Core_Resources
- load() : $this
- Calling this method from outside this class is deprecated.
- onRegionRender() : mixed
- Loader service callback when rendering a page region.
- setAngular() : AngularLoader
- setPageName() : AngularLoader
- setRegion() : AngularLoader
- setRes() : AngularLoader
- useApp() : AngularLoader
- Use Civi's generic "application" module.
- isAllModules() : int
- loadAngularResources() : mixed
- Load scripts, styles & settings for the active modules.
Constants
DEFAULT_MODULE_WEIGHT
The weight to assign to any Angular JS module files.
public
mixed
DEFAULT_MODULE_WEIGHT
= 200
Properties
$angular
The Angular module manager.
protected
Manager
$angular
Do not use publicly. Inject your own copy!
$crmApp
protected
array<string|int, mixed>|null
$crmApp
= NULL
$modules
protected
array<string|int, mixed>
$modules
A list of modules to load.
$modulesAlreadyLoaded
protected
array<string|int, mixed>
$modulesAlreadyLoaded
= []
When adding supplimental modules via snippet, these modules are already loaded.
$pageName
protected
string
$pageName
Ex: 'civicrm/a'.
$region
The region of the page into which JavaScript will be loaded.
protected
string
$region
$res
The resource manager.
protected
CRM_Core_Resources
$res
Do not use publicly. Inject your own copy!
Methods
__construct()
AngularLoader constructor.
public
__construct() : mixed
addModules()
public
addModules(array<string|int, mixed>|string $modules) : AngularLoader
Parameters
- $modules : array<string|int, mixed>|string
Return values
AngularLoaderfindActiveModules()
Get a list of all Angular modules which should be activated on this page.
public
findActiveModules() : array<string|int, mixed>
Return values
array<string|int, mixed> —List of module names. Ex: array('angularFileUpload', 'crmUi', 'crmUtil').
getAngular()
public
getAngular() : Manager
Return values
ManagergetModules()
public
getModules() : array<string|int, mixed>
Return values
array<string|int, mixed>getPageName()
public
getPageName() : string
Return values
string —Ex: 'civicrm/a'.
getRegion()
public
getRegion() : string
Return values
stringgetRes()
public
getRes() : CRM_Core_Resources
Return values
CRM_Core_Resourcesload()
Calling this method from outside this class is deprecated.
public
load() : $this
Use the angularjs.loader
service instead.
Return values
$thisonRegionRender()
Loader service callback when rendering a page region.
public
onRegionRender(GenericHookEvent $e) : mixed
Loads Angular resources if any modules have been requested for this page.
Parameters
- $e : GenericHookEvent
setAngular()
public
setAngular(Manager $angular) : AngularLoader
Parameters
- $angular : Manager
Return values
AngularLoadersetPageName()
public
setPageName(string $pageName) : AngularLoader
Parameters
- $pageName : string
-
Ex: 'civicrm/a'.
Return values
AngularLoadersetRegion()
public
setRegion(string $region) : AngularLoader
Parameters
- $region : string
Return values
AngularLoadersetRes()
public
setRes(CRM_Core_Resources $res) : AngularLoader
Parameters
- $res : CRM_Core_Resources
Return values
AngularLoaderuseApp()
Use Civi's generic "application" module.
public
useApp([array<string|int, mixed> $settings = [] ]) : AngularLoader
This is suitable for use on a basic, standalone Angular page
like civicrm/a
. (If you need to integrate Angular with pre-existing,
non-Angular pages... then this probably won't help.)
The Angular bootstrap process requires an HTML directive like
<div ng-app="foo">
.
Calling useApp() will replace the page's main body with the
<div ng-app="crmApp">...</div>
and apply some configuration options
for the crmApp
module.
Parameters
- $settings : array<string|int, mixed> = []
-
A list of settings. Accepted values:
- activeRoute: string, the route to open up immediately Ex: '/case/list'
- defaultRoute: string, use this to redirect the default route (
/
) to another page Ex: '/case/list' - region: string, the place on the page where we should insert the angular app Ex: 'page-body'
Tags
Return values
AngularLoaderisAllModules()
private
isAllModules(mixed $moduleNames) : int
Parameters
- $moduleNames : mixed
Return values
intloadAngularResources()
Load scripts, styles & settings for the active modules.
private
loadAngularResources() : mixed