I am kind of stuck here. I have an application which uses bootstrap modal with couple of text boxes which has values from server. When i open the modal for the first time and remove the items from textbox ng-change event fires. Once all the fields are cleared, i closed the modal. When i opened the modal again it is populated with new values but when i remove the item from the textbox ng-change event is not triggered.
我有点被困在这里。我有一个应用程序使用bootstrap模式与几个文本框,其中包含来自服务器的值。当我第一次打开模态并从文本框中删除项目时更改事件触发。清除所有字段后,我关闭了模态。当我再次打开模态时,它会填充新值,但是当我从文本框中删除项目时,不会触发ng-change事件。
But here i found one more strange thing, the above mentioned problem occurs only if we have one item in textbox.
但是在这里我发现了一个更奇怪的事情,只有在文本框中有一个项目时才会出现上述问题。
Here is my html code:
这是我的HTML代码:
<tr>
<td>
<input only-numeric class="floatLeft" name="scoreSample" type="text" ng-model="scoreSample" id="scoreSample" ng-change="sampleMethod()" ng-model-onblur>
</td>
<td>
<input only-numeric class=" floatLeft" name="errorSample" type="text" ng-model="errorSample" id="errorSample" ng-change="sampleMethod()" ng-model-onblur>
</td>
</tr>
AngularJS code:
AngularJS代码:
$scope.sampleMethod = function () {
alert("Coming here");
}
Thanks in advance.
提前致谢。
1 个解决方案
#1
1
Possible reasons for this happening are listed in the documentation:
发生这种情况的可能原因列在文档中:
The ngChange expression is only evaluated when a change in the input value causes a new value to be committed to the model.
仅当输入值的更改导致将新值提交给模型时,才会评估ngChange表达式。
It will not be evaluated:
它不会被评估:
if the value returned from the $parsers transformation pipeline has not changed
如果从$ parsers转换管道返回的值没有改变
if the input has continued to be invalid since the model will stay null
如果输入继续无效,因为模型将保持为空
if the model is changed programmatically and not by a change to the input value Note, this directive requires ngModel to be present.
如果以编程方式更改模型而不是通过更改输入值注意,则此指令需要存在ngModel。
Have you checked these things? Other than that I also think you should post the entire view and controller as it is very difficult to find an error in the snippet you posted already.
你检查过这些东西了吗?除此之外我还认为你应该发布整个视图和控制器,因为很难在你发布的代码片段中找到错误。
#1
1
Possible reasons for this happening are listed in the documentation:
发生这种情况的可能原因列在文档中:
The ngChange expression is only evaluated when a change in the input value causes a new value to be committed to the model.
仅当输入值的更改导致将新值提交给模型时,才会评估ngChange表达式。
It will not be evaluated:
它不会被评估:
if the value returned from the $parsers transformation pipeline has not changed
如果从$ parsers转换管道返回的值没有改变
if the input has continued to be invalid since the model will stay null
如果输入继续无效,因为模型将保持为空
if the model is changed programmatically and not by a change to the input value Note, this directive requires ngModel to be present.
如果以编程方式更改模型而不是通过更改输入值注意,则此指令需要存在ngModel。
Have you checked these things? Other than that I also think you should post the entire view and controller as it is very difficult to find an error in the snippet you posted already.
你检查过这些东西了吗?除此之外我还认为你应该发布整个视图和控制器,因为很难在你发布的代码片段中找到错误。