Created
November 27, 2016 10:30
-
-
Save ilikerobots/398b34f5c5a2f5bcf36aea6d3e63ae9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef String TitleNamingFunction(ComponentInstruction c); | |
| @Injectable() | |
| class TitleSetService { | |
| TitleNamingFunction nameStrategy; | |
| Router _router; | |
| Title _title; | |
| TitleSetService(this._router, this._title) { | |
| nameStrategy = _defaultNameStrategy; | |
| _router.subscribe(_setTitleFromRoute); | |
| } | |
| Future<Null> _setTitleFromRoute(String url) async { | |
| //identify component instruction from routed url | |
| ComponentInstruction compInst = (await _router.recognize(url))?.component; | |
| if (compInst != null) { | |
| _title.setTitle(nameStrategy(compInst)); | |
| } | |
| } | |
| String _defaultNameStrategy(ComponentInstruction compInst) { | |
| return compInst.routeName; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment