I’ve got a modal component and in one of templates that is displayed inside this component I need to display the current URL as a value of text input element.
I’ve created currentURL helper that simply returns window.location.href and it works fine, but I don’t know how to use this helper to set value attribute of text input element, because it looks like bind-attr expects a property on the current context and not a helper.
I probably could set it as a property on controller/view, but I’m not sure how to do it using Route#render method. Currently I’m rendering modals like this:
Got it… I created a view for this specific template with currentURL property and I pass this property to the component in the template - {{#modal-dialog currentURL=view.currentURL}}.
Thanks! I actually need the whole URL to allow users to easily share it, but this way I could add currentURL property on application controller that would observe currentPath instead of creating a separate view just for this single property.
A computed property will work in this case since they’re async, where observers are immediate (mentioned @ emberconf that it’s a possible bug in Ember that has lingered around). So that’s why it’s needed to wrap in an Ember.run.next within an observer because the change to window.location.href actually happens later on in routerTransitions run loop queue.
I could be wrong, but I believe that’s the reason.
I finally had some time to get back to this app and, unfortunately, observing currentPath doesn’t work correctly.
I’ve got a route named room where the path looks like /rooms/:room_id and whatever room_id is, currentPath always returns just room, so the currentUrl is not updated when user switches between rooms…
It also looks like in setupController function, URL is not modified yet, so I can’t set currentURL property there on controller as well.