简体   繁体   English

Angular.js变量绑定

[英]Angular.js variable binding

I have simple angular web application and form on it. 我有简单的angular Web应用程序和表格。 Form contains 2 <input> and 1 <p> elements. 表单包含2个<input>和1个<p>元素。 p value is angular template: p值是angular模板:

<p>{{status()}}</p>

$scope.status = function(){
    alert('p');
    return 'Some status';
}

When page loaded all displays normally i see alert and 'Some status' in my <p> . 页面加载后,所有显示正常,我在<p>看到警报和'Some status' But I have a question. 但是我有一个问题。 When i try to input something to the <input> , i see alert('p') again and again every time when i typing any symbol to the input ? 当我尝试输入一些东西到<input> ,我看到alert('p')一遍又一遍,当我键入任何符号的每一次input Why? 为什么?

Thank you. 谢谢。

I guess you have an input with ng-model. 我想您有ng-model输入。 When your input is modified, the model is changed. 修改输入后,将更改模型。 After each change, angular runs the digest, which reevaluates all the expressions in the view (technically it processes the watch list). 每次更改后,angular运行摘要,它重新评估视图中的所有表达式(从技术上讲,它处理监视列表)。 You should read about it in the Angular concepts in the Angular developer guide . 您应该在Angular开发人员指南Angular概念中阅读有关它的内容。

我认为您在输入上也有数据绑定,这就是为什么每次使用键输入更改某些内容时angular都会验证范围,并调用警报,因为angular必须执行该函数来检查返回的值是否仍然相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM