-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(sidenav): allow for data bindings in md-component-id #9255
Conversation
I think @EladBezalel had something similar, including observation of the attribute. #5972 |
Seems like it didn't end up getting merged. @EladBezalel is it ok if I incorporate the changes here? |
053d671
to
4cc21fe
Compare
Updated, although the approach from #5972 doesn't work for cases where the instance is being looked up in a controller on load (like in the sidenav demo). |
self.destroy = $mdComponentRegistry.register(self, componentId); | ||
|
||
// Watch and update the component, if the id has changed. | ||
$attrs.$observe('mdComponentId', function(id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we only do this if we originally had interpolation symbols ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah, good point. I'll change it.
Fixes the sidenav not evaluating expressions inside of the `md-component-id` attribute. Fixes angular#9052.
4cc21fe
to
4341757
Compare
self.destroy = $mdComponentRegistry.register(self, $attrs.mdComponentId); | ||
// Evaluate the component id. | ||
var rawId = $attrs.mdComponentId; | ||
var hasDataBinding = rawId && rawId.indexOf($interpolate.startSymbol()) > -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is mdComponentId
a directive?
If so why isn't that check happens on the directive? if not let's make it a directive.. looks like it should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a directive, it's just the attribute that you use to pass the id. I'm not sure it make sense for it to be a directive since it's just a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be an attribute directive that checks if it should watch for changes or not (like mdColors does)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still seems redundant and won't be immefiately obvious where the id is coming from. In this case it's right next to the initialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the discussion on Slack, let's keep this in here for now and do a more generic solution if the need for one comes up.
Fixes the sidenav not evaluating expressions inside of the `md-component-id` attribute. Fixes angular#9052.
Fixes the sidenav not evaluating expressions inside of the
md-component-id
attribute.Fixes #9052.