【发布时间】:2019-07-20 14:55:03
【问题描述】:
这是视图中的代码:
<input type="radio" name="tabset" id="tab2" aria-controls="rauchbier"
ng-checked="switch_tabs()">
这就是控制器中的代码
$scope.switch_tabs = function(){
console.log(notification_form_data);
console.log($('#notification_form').serialize());
if (notification_form_data != $('#notification_form').serialize() & notification_form_data!= undefined)
{
var alertPopup = $ionicPopup.alert({
title: 'vs',
template: 'unsaved data in actions',
button: 'Done'
});
}
当条件 = true 时,警报和 console.log 发生 100 次,如何仅触发 1 次
【问题讨论】:
-
id为
notification_form的元素是什么?为什么要将 jQuery 与 AngularJS 混合使用?每当你这样做时,你就是在自找麻烦。 -
只要
ng-checked指令有一个作为函数的AngularJS 表达式,该函数将在每个摘要循环中被多次调用,直到返回值稳定。它总是至少被调用两次。
标签: javascript angularjs