-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(bhCurrencySelect): currency selection radios #178
Conversation
} | ||
}); | ||
|
||
bhCurrencySelect.$inject = [ '$scope', 'CurrencyService' ]; |
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.
Don't inject the all scope
, the component should not access the whole scope
.
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 use $scope.$watch()
. Can you give some example code that does the same thing and does not use $scope.$watch()
?
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.
@DedrickEnc, could you please give me feedback on how to make this code better? I do not know a better way than this. What suggestions do you have?
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.
@jniles , I have an idea and I think it good.
When reading the component documentation, I understood that, the component is only responsible of his own view, that is why is scope is always isolated.
In theory you can access the entire view of the page where a component is injected by using scope
and watch
but this is a bad practice.
When improving currency input, I faced the same problem, I was supposed to use scope
but I have an other alternative, using the component tree design.
So for the currency input for exemple, I will need the currency select first, so when a user change the currency, the currency select component will call an appropriate method of currency input. so the currency input will update his view and apply specific validation rule.
I will use your code (currency select) to perform it. And will submit the PR this evening, so you will review it.
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 do realize that $scope
isn't the entire $scope
of the page right? It is an isolated scope. In this component's case, the only thing attached to the $scope
is the child form found inside the component.
I'll be interested to see your design.
c4d7f13
to
f2b86bd
Compare
So, after some research, here was I have discovered about AngularJS's scopes.
Honestly, I do not think the This is not the only way to achieve the functionality of disabling ids. Here is are some other ways of doing this:
|
This commit introduces the bhCurrencySelect radio component to select currencies in forms. The basic signature looks like this: ```html <!-- simple usage --> <bh-currency-select currency-id="ParentCtrl.model.currencyId" validation-trigger="ParentForm.$submitted" > </bh-currency-select> <!-- complex usage: disable currencies based on ids found in the disable-ids array and register an ngChange event. --> <bh-currency-select currency-id="ParentCtrl.model.currencyId" on-change="ParentCtrl.currencyChangeEvent()" disable-ids="ParentCtrl.disabledIds" validation-trigger="ParentForm.$submitted" > </bh-currency-select> ``` See the source code for implementation details. The list of supported bindings follows: 1. [currency-id] - the model value for the underlying `<input>`s. This is two-way bound to the parent controller. 2. [validation-trigger] (_optional_) - a boolean that can be passed in to show validation messages will only show if this boolean is true. It is useful to bind `ParentForm.$submitted` value to this attribute. 3. [on-change] (_optional_) - a callback bound the `ng-change` event on the `<input>`s. 4. [disable-ids] (_optional_) - an array of currency ids to be disabled as required. An implementation of the most complex case is given in the cash module. Partially addresses #106.
f2b86bd
to
4c44179
Compare
Since I've received no feedback on why this is a bad design and no reference documentation to where someone recommends against using $scope.$watch in this scenario, I'm going to close this. |
This commit introduces the bhCurrencySelect radio component to select
currencies in forms. The basic signature looks like this:
See the source code for implementation details. The list of supported
bindings follows:
<input>
s. This is two-way bound to the parent controller.ParentForm.$submitted
value to this attribute.ng-change
event on the<input>
s.An implementation of the most complex case is given in the cash module, with passing end to end tests.
There is also a currency component wrapper that works as you would expect:
Partially addresses #106.