ngChange is called when model changed programmatically

前端 未结 4 1650
旧时难觅i
旧时难觅i 2021-02-08 06:15

I have a problem when angular\'s ng-change is called when model is changed programmatically.

$scope.sendMessage = function() {
    $scope.message = \"Message sen         


        
4条回答
  •  梦如初夏
    2021-02-08 07:01

    The ng-change callback is changed on each model change, and it treats the initial setup as such change. What you might want to do is to run desired code only after user interacts with it. You can check the $touched property of the field:

    message = {{message}}

    $scope.sendMessage = function() { if ($scope.exampleForm.mySelectBox.$touched) { $scope.message = "Message sent"; } }

提交回复
热议问题