-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(sidenav): allow for data bindings in md-component-id #9255
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,8 +249,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate, | |
}, | ||
controller: '$mdSidenavController', | ||
compile: function(element) { | ||
element.addClass('md-closed'); | ||
element.attr('tabIndex', '-1'); | ||
element.addClass('md-closed').attr('tabIndex', '-1'); | ||
return postLink; | ||
} | ||
}; | ||
|
@@ -481,9 +480,8 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate, | |
* @ngdoc controller | ||
* @name SidenavController | ||
* @module material.components.sidenav | ||
* | ||
*/ | ||
function SidenavController($scope, $element, $attrs, $mdComponentRegistry, $q) { | ||
function SidenavController($scope, $attrs, $mdComponentRegistry, $q, $interpolate) { | ||
|
||
var self = this; | ||
|
||
|
@@ -505,5 +503,21 @@ function SidenavController($scope, $element, $attrs, $mdComponentRegistry, $q) { | |
self.toggle = function() { return self.$toggleOpen( !$scope.isOpen ); }; | ||
self.$toggleOpen = function(value) { return $q.when($scope.isOpen = value); }; | ||
|
||
self.destroy = $mdComponentRegistry.register(self, $attrs.mdComponentId); | ||
// Evaluate the component id. | ||
var rawId = $attrs.mdComponentId; | ||
var hasDataBinding = rawId && rawId.indexOf($interpolate.startSymbol()) > -1; | ||
var componentId = hasDataBinding ? $interpolate(rawId)($scope.$parent) : rawId; | ||
|
||
// Register the component. | ||
self.destroy = $mdComponentRegistry.register(self, componentId); | ||
|
||
// Watch and update the component, if the id has changed. | ||
if (hasDataBinding) { | ||
$attrs.$observe('mdComponentId', function(id) { | ||
if (id && id !== self.$$mdHandle) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the id that is assigned when an element is registered with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.destroy(); // `destroy` only deregisters the old component id so we can add the new one. | ||
self.destroy = $mdComponentRegistry.register(self, id); | ||
} | ||
}); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
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.