I need to pas params to Aurelia on start. Depending on values passed the application will have diffrent state. This application is injected on page which is build with PHP, so the best way would be starting it with parameters specified with PHP code. Is there any way to do this?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- Laravel Option Select - Default Issue
- How to toggle on Order in ReactJS
- PHP Recursively File Folder Scan Sorted by Modific
Any data you can access in normal JS you can access with Aurelia. Maybe you could use a
data-*
attribute to do this? When you use amain
file by doingaurelia-app="main", the framework instance you get passed to your configure method has a
hostproperty that is the element the framework is being attached to. You could place
data-*attributes on this element and then access them via the
dataset` property of this element (IE11+ https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset).Your
index.html
or equivalent might have something like this:Your
main.js
can then access these values easily:Here is a runnable example: https://gist.run/?id=55eae2944b00b11357868262e095d28c
You could even put JSON in the data attribute if you use single quotes around the attribute value: https://gist.run/?id=57417139aa8c0c66b241c047efddf3dd
Edit: I've improved this answer based on the similar answer Jeremy Danyow posted. Both linked gists have been updated as well.