-
Notifications
You must be signed in to change notification settings - Fork 3.4k
md-input directive #848
md-input directive #848
Conversation
CLAs look good, thanks! |
// Copy relevant attributes down to the input element: attrs that either aren't a directive, | ||
// or are a directive that has already run (a directive with higher priority) | ||
// For example, ng-if would NOT be copied down to the input because it has a higher priority | ||
angular.forEach(node.attributes, function(data) { |
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.
Could attr
be used instead of node.attributes
?
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.
I guess there are other implications if attr
was used (e.g. using getAttribute()
to get the original (non-interpolated) value of the attribute etc).
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.
You're right, I should be using the compile
function to get the un-interpolated values.
@ajoslin: Have you evaluated the alternative of having a specific prefix for "transferrable" attributes ? Are there any drawbacks to that (which I might not have thought of) ? E.g.:
Pros:
Cons: ?? |
@gkalpak interesting idea! The con of course is that the developer won't be able to use the attribute names he is accustomed to. Hmm.. |
I do not thinks this is a good idea as I worry that developers will have to learn which attributes (with prefixes) are supported... this is a verbose solution instead of concise. |
The problem of Directives with higher priority execute on the parent element, not the input: this makes sense. Directives with 0 priority that should execute on the parent element: what to do? |
Actually, it is the other way around (maybe I wasn't clear enough).
This coupling between unrelated things (directive priorities, attributes transfered) is only going to create headaches for both the developers and maintainers alike. That said, (and despite me being all against verbosity in general), I do believe that the verbosity in my proposal is minimal and justified by the benefits*. *: In fact it's not exactly benefits; it's avoiding the alternative solution's drawbacks. A totally different approach might be way better that both alternatives. |
Talking about alternative approaches, here are a couple more suggestions
|
As @gkalpak has mentioned, I've brought this up for 1.x --- and a few weeks ago, proposed this for 2.x as an alternative to the If we did move this into 1.x, it could work well here |
I support the attribute prefix approach for passing it down to the concrete elements, specially when you consider that there is also a "label" element inside the md-text-float directive. How do we know which attributes should be passed down to the label or to the input? If we agree on a simple naming convention, for instance: md-text-float-input-attr- and md-text-float-label-attr- then developers won't have to learn new attributes, just know the naming convention. And there's no other complications such as priorities, transclusions, etc. |
I think it should support regular attributes, as those are what people are used to and will minimize confusion. |
var input = angular.element(element[0].querySelector( | ||
(angular.isDefined(attr.mdMultiline) ? 'textarea' : 'input') + ':last-of-type' | ||
)); | ||
var ngModelCtrl = input.data('$ngModelController'); |
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 this not be:
var ngModelCtrl = input.controller('ngModel');
Or does that look at inherited data too?
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 does --- but for ng-model that does not seem like an issue, in general
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.
Yes, it looks at inherited data. I just did that incase a parent has a model and the input doesn't.
Went with a different approach. 60fcd6f |
Old problem: We didn't know what attributes to pass down to the input directive from the input container.
Solution: We have a directive with priority 100 and
terminal: true
.terminal
means that no directive with lower priority will run on this element - basically, directive compilation will stop atmd-input
.With
priority: 100
,md-input
still runs afterng-if
,ng-repeat
, etc.When
md-input
runs, it takes all attributes on<md-input>
container and copies them down to a child<input>
element - EXCEPT attributes that are directives with higher priority (like ng-if).PROBLEMS