[英]Angularjs : How to prevent ng-change triggered after loading the page when ng-change connected to a datepicker input?
我在這里有一些關於datepicker輸入和ng-change指令的問題。 似乎是在加載頁面時觸發了更改,因為datepicker位於js文檔就緒函數中。 如果可能的話,我怎么能阻止它? 謝謝
index.html:
<input
id="birthDate"
style="width:250px;"
class="form-control"
type="text"
ng-model="data.birth_date"
ng-change="postHelloWorld()"
/>
$(document).ready(function() {
$('#birthDate').datepicker({
format : 'yyyy-mm-dd'
});
})
控制器:
$scope.postHelloWorld = function() {
alert('hello World!');
}
這里的問題是加載頁面后始終顯示的警報。
在這里,我更新您的代碼。 它為我工作。 請檢查你出錯的地方。
<html ng-app="myApp">
<body ng-controller="sampleCtrl">
<input
id="birthDate"
style="width:250px;"
class="form-control"
type="text"
ng-model="data.birth_date"
ng-change="postHelloWorld()" />
</body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
$(document).ready(function() {
$('#birthDate').datepicker({
format : 'yyyy-mm-dd'
});
})
var app = angular.module('myApp', []);
app.controller('sampleCtrl', function($scope) {
$scope.postHelloWorld = function(){
alert("Hello World " + $scope.data.birth_date);
}
});
</script>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.