
本文介绍了Angular ng-change 不调用代码.我是否使用了错误的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 MEAN.js 生成器和我在网上找到的教程构建一个应用程序.在这里,我的一个 Angular 视图中有一个日期选择器.现在我希望 ng-change 指令被识别并做一些事情.在我更改日期时,此处显示的测试警报没有被调用.
<label class="control-label" for="statusdate">状态日期</label><div class="控件"><input type="date" ng-change="alert('something')" data-ng-model="statusDate" id="statusdate" class="form-control">
有人可以帮忙吗?我是 Angular 的新手.
另外,我在某处读到它可能是因为我使用了 data-ng-model 而不是 ng-model.可能是这种情况吗?如果是,那么两者有什么区别?
解决方案
您正在执行控制器中不存在的方法.
尝试像这样创建它:
$scope.alert = function(msg) {警报(味精);};
I am building an app using MEAN.js generators and a tutorial I found online. Here I have a datepicker in one of my Angular views. For now I would like the ng-change directive to be recognized and do something. At the moment when I make a change to the date my test alert shown here does not get called.
<div class="form-group">
<label class="control-label" for="statusdate">Status Date</label>
<div class="controls">
<input type="date" ng-change="alert('something')" data-ng-model="statusDate" id="statusdate" class="form-control">
</div>
</div>
Can somebody help? I am new to Angular.
Also, I read somewhere it may be because I used data-ng-model as opposed to ng-model. Could this be the case? If so then what is the difference between the two?
解决方案
You are executing a method that does not exist in the controller.
Try creating it like this:
$scope.alert = function(msg) {
alert(msg);
};
这篇关于Angular ng-change 不调用代码.我是否使用了错误的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!