<!DOCTYPE html>
<html ng-app="myApp">
<head>
  <meta charset="UTF-8">
  <title>AngularJS Data Binding Example</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.9/angular.min.js"></script>
</head>
<body>
  <div ng-controller="myCtrl">
    <h2>AngularJS Data Binding Example</h2>
    <p>Input something in the input box:</p>
    <input type="text" ng-model="inputText">
    <p>The value of input box is: {{inputText}}</p>
  </div>
  <script>
    var app = angular.module("myApp", []);

    app.controller("myCtrl", function($scope) {
      $scope.inputText = "";

      $scope.$watch("inputText", function(newValue, oldValue) {
        console.log("New value: " + newValue);
        console.log("Old value: " + oldValue);
      });
    });
  </script>
</body>
</html>
用htnl写一个调用angularjs的作用域上的数据监听例子

原文地址: https://www.cveoy.top/t/topic/Fw9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录