First of all, can I correct a small flaw in wording.
You said "$watch monitors a drop-down box", ng是一个实现数据双向绑定的,具有声明式API的框架,这里的$watch是不可能去监视一个DOM元素下拉框that's right. The appropriate wording can be written as "an expression monitored by $watch that points to the selected value of the drop-down box" which is more accurate (friends who are good at Chinese can further optimize).
When asking questions, we tend to focus too much on the answers we want to know and ignore the way of expression. As a result, we often end up in vain. This type of question is very common in SF. The questioner’s description is vague, making it impossible to answer. In fact, I can still understand the description of the question, but I just want to say a few more words because of my feelings.
Back to the subject, since you don’t want to process the data initialization time$watch, you can judge it like this
Using a program to change the value of ngModel will not trigger ngChange
Evaluate the given expression when the user changes the input. The expression is evaluated immediately, unlike the JavaScript onchange event which only triggers at the end of a change (usually, when the user leaves the form element or presses the return key).
Thanks for the invitation.
First of all, can I correct a small flaw in wording.
You said "$watch monitors a drop-down box",
ng
是一个实现数据双向绑定的,具有声明式API的框架,这里的$watch
是不可能去监视一个DOM元素下拉框
that's right. The appropriate wording can be written as "an expression monitored by $watch that points to the selected value of the drop-down box" which is more accurate (friends who are good at Chinese can further optimize).When asking questions, we tend to focus too much on the answers we want to know and ignore the way of expression. As a result, we often end up in vain. This type of question is very common in SF. The questioner’s description is vague, making it impossible to answer. In fact, I can still understand the description of the question, but I just want to say a few more words because of my feelings.
Back to the subject, since you don’t want to process the data initialization time
$watch
, you can judge it like thisUse ngChange to avoid initialization calls
Attention:
Needs to be used together with ngModel
Using a program to change the value of ngModel will not trigger ngChange
ngChange Documentation