zoukankan      html  css  js  c++  java
  • ionic准备之angular基础——$watch,$apply,$timeout方法(5)

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body ng-app="myApp">
    
        <!--$watch用法-->
        <div ng-controller="firstController">
            数量:<input type="text" ng-model="amount"><br>
            价格:{{price}}<br>
            总计:{{sum}}<br>
        </div>
    
        <!--apply用法-->
        <div ng-controller="secondController">{{num}}</div>
    
    
        <!--$timeout用法-->
        <div ng-controller="threeController">{{num}}</div>
    </body>
    <script src="angular/angular.js"></script>
    <script type="text/javascript">
        var app=angular.module("myApp",[]);
    
        app.controller('firstController',function($scope){
           $scope.amount=123;
           $scope.price=20;
           $scope.sum= $scope.amount*$scope.amount;
           $scope.$watch('amount',function(newValue,oldValue){   //更新amount变化
              $scope.sum=newValue*$scope.price;
           });
        })
    
        /*$apply用法*/
        app.controller('secondController',function($scope){
            $scope.num=20;
            setTimeout(function(){
                $scope.num=30;
                $scope.$apply();    /*更新view*/
            },1500);
        })
    
        /*$timeout用法*/
        app.controller("threeController",function($scope,$timeout){
            $scope.num=20;
            $timeout(function(){
                $scope.num=30;
            },1200);
        });
    
    
    </script>
    </html>
    

      

  • 相关阅读:
    NS3笔录
    网络性能指标的几个定义
    获取Emum类型值的数量
    Container类型元素累加
    ax用代码调用静态查询
    FormRun类的方法detach()作用
    Num2Str函数使用介绍
    查询生产单PO的位置
    AX使用临时表作为数据源
    Date2Str函数使用介绍
  • 原文地址:https://www.cnblogs.com/tanxu/p/5320534.html
Copyright © 2011-2022 走看看