search

Home  >  Q&A  >  body text

angular.js watch 监听不到input的值的变化

<input type="text" name="name" ng-model="inputname" ng-init="inputname='hello'">
       <span>{{inputname}}</span>
    <button type="button" name="button" ng-click="change()">改变值</button>
$scope.change=function(){
 $scope.inputname="world";
}
$scope.$watch("$scope.inputname",function(newValue,oldValue){
   console.log(newValue);
   console.log(oldValue);
   console.log($scope.inputname);
})
过去多啦不再A梦过去多啦不再A梦2744 days ago528

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 17:06:38

    $watchWrong method

    $scope.$watch('inputname', function(newValue,oldValue){
       console.log(newValue);
       console.log(oldValue);
       console.log($scope.inputname);
    })

    reply
    0
  • Cancelreply