-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(chips): trigger ng-change on chip addition/removal #11166
Conversation
Sorry for more commit message confusion. |
72c6242
to
12134e2
Compare
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.
Thank you for your contribution!
- Please add the appropriate docs (as comments) in the
chipsDirective.js
andcontactChipsDirective.js
files for supportingng-change
. - Can you please add the use of
ng-change
to the current Contact Chips demo? - Can you please add a demo for
ng-change
that covers normal Chips? - Can you please add a test to the
contact-chips.spec.js
file?
12134e2
to
ba5e72e
Compare
@Splaktar Why do we need a test of |
OK, that test may not be needed, as long as we can see it working in the demo. It still seems somewhat useful to have though to make sure that some change to |
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.
Updated changes LGTM, but I still need to do some manual testing.
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 just added two more comments with rly small stuff but to increase clean code in my opinion, but i like the PR overall very much!
@@ -122,6 +124,7 @@ function MdContactChips($mdTheming, $mdUtil) { | |||
contactImage: '@mdContactImage', | |||
contactEmail: '@mdContactEmail', | |||
contacts: '=ngModel', | |||
ngChange: "&", |
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.
Why double quote here when all the other bindings have single quote?
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.
Opss, it just a matter of habit. In the project I'm working on we use double quotes. I'll fix.
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.
In the meantime I've fixed this.
@@ -329,6 +329,7 @@ MdChipsCtrl.prototype.updateChipContents = function(chipIndex, chipContents){ | |||
if(chipIndex >= 0 && chipIndex < this.items.length) { | |||
this.items[chipIndex] = chipContents; | |||
this.ngModelCtrl.$setDirty(); | |||
this.ngModelCtrl.$setViewValue(this.items.slice()); |
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.
Since this line is repeated 3-times - why not wrap it into a helper-function similar to validateModel() ?
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 seems there is already a function called validateModel
and I think that updateModel
describes better what does this statement do.
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.
But do we really need an helper function for just a single line of instruction?
On the other hand, if you meant to wrap into a function the two lines that are repeated
this.ngModelCtrl.$setDirty();
this.ngModelCtrl.$setViewValue(this.items.slice());
then I think we can remove this.ngModelCtrl.$setDirty()
, since AFAIK $setViewValue()
should already set the model as $dirty
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.
oh, I maybe choosed the wrong words. I meant something like the validateModel(), not name it this way.
But it is 3-times calling a function $setViewValue
and chooses the a copy (slice()
) from the inner value-cache (this.items
). Maybe there is a small change there so the developer has to update now 3-lines instead of one.
This is just an suggestion to wrap this in an extra function because I like to reduce repeated code and make it easier to maintain. But every developer has different workflows.
PS.: if this helper-function could also reduce other duplications it is even better.
36ec784
to
4928ed3
Compare
@IMM0rtalis |
@@ -39,5 +40,9 @@ | |||
type: 'unknown' | |||
}; | |||
}; | |||
|
|||
self.onModelChange = function(newModel) { | |||
alert("The model has changed"); |
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.
Can you please use single quotes here?
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.
Fixed
@@ -84,6 +85,10 @@ | |||
|
|||
} | |||
|
|||
function onModelChange(model) { | |||
alert("The model has changed"); |
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.
Can you please use single quotes here?
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.
Fixed
* Add test of `ng-change` for `md-chips` * Add docs regarding `ng-change` for `md-chips` and `md-contact-chips` * Add demo for ng-change on `md-chips` * Add demo for ng-change on `md-contact-chips` Closes angular#11161 Closes angular#3857
4928ed3
to
73bfa8a
Compare
Testing done. Submitting to presubmit. |
…lar#11166)" This reverts commit 19da42d.
I'm not sure what the details are yet, but there may be some issue with these changes that may require reverting them. Just a heads up. More details may be available in #11214 at some point. |
@@ -584,16 +582,21 @@ MdChipsCtrl.prototype.validateModel = function() { | |||
this.ngModelCtrl.$validate(); // rerun any registered validators | |||
}; | |||
|
|||
MdChipsCtrl.prototype.updateNgModel = function() { | |||
this.ngModelCtrl.$setViewValue(this.items.slice()); |
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.
* Add test of `ng-change` for `md-chips` * Add docs regarding `ng-change` for `md-chips` and `md-contact-chips` * Add demo for ng-change on `md-chips` * Add demo for ng-change on `md-contact-chips` Closes angular#11161 Closes angular#3857
* Revert "feat(chips): trigger ng-change on chip addition/removal (angular#11166)" This reverts commit 19da42d. * Revert "feat(md-chips): added validation for ng-required (angular#11125)" This reverts commit ba0e9fe.
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
ng-change
is not supported formd-chips
ormd-contact-chips
.Issue Number:
#11161 #3857
What is the new behavior?
ng-change
is supported onmd-chips
. It will be triggered on chip addition/removal.Does this PR introduce a breaking change?
Other information
Closes #11161 and #3857