angularJS 入门基础(8)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>angular</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <script src=""></script>
    <script src=""></script>
    <link href="">
    <script src="" type="text/javascript"></script>
</head>
<body ng-app="app">
    <script type="text/javascript">
           var app = angular.module("app",[]);
    </script>
    <div>
        <div>
            <span>update</span>angular的通知数据更新三种方式$scope.$digest(),$scope.$apply(),以及通过$scope.$watch监听进行更新;
        </div>
        <div ng-controller="apply">
            {{hehe}}
            <input type="text" ng-model="m0" />
            <div>
                the value set by $scope.$watch ==>> {{wat}}
            </div>
            <br>
            <button ng-click="up()">
                applay;
            </button>
        </div>
        <script type="text/javascript">
            app.controller("apply", function($scope) {
                $scope.hehe = "lll________xxx";
                $scope.m0 = 1;
                ss = $scope;
                $scope.up = function() {
                    $scope.hehe = $scope.m0;
                    //可以,但是给了提示的报错, 谁知道为甚毛?
                    //$scope.$apply();
                    $scope.$digest();
                };
                             //给$scope.m0变量是无效的;
                $scope.$watch("m0", function(va) {
                    $scope.wat = va;
                })
            });
        </script>
    </div>
</body>
</html>

angular中自己定义的工具方法

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfxjj.html