• [AngularJS] Angular 1.3 new $q constructor


    <!DOCTYPE html>
    <html ng-app="app">
    <head lang="en">
        <meta charset="UTF-8">
        <title>new $q constructor </title>
        <script src="bower_components/angular/angular.min.js"></script>
        <script src="app.js"></script>
    </head>
    <body ng-controller="MainCtrl as vm">
        <button ng-click="vm.fire(true)">Reject it</button>
        <button ng-click="vm.fire(false)">Resolve it</button>
        <h3>Last Resolved Value</h3>
        <pre>{{vm.resolveData | json}}</pre>
    
        <h3>Last Rejected Value</h3>
        <pre>{{vm.rejectData | json}}</pre>
    </body>
    </html>
    /**
     * Created by Answer1215 on 11/13/2014.
     */
    function MainCtrl($q){
        'use strict';
        var vm = this;
        vm.fire = fire;
        vm.resolveData = null;
        vm.rejectData = null;
    
        function fire(rejectIt){
            console.log('fire');
            doAsync(rejectIt).then(function(data){
                vm.resolveData = data;
            }, function(error){
                vm.rejectData = error;
            });
        }
    
        //$q usually sepreate from the logic
        function doAsync(rejectIt){
            return $q(function(resolve, reject){
                setTimeout(function(){
                    var doneTime = +new Date();
                    console.log(doneTime);
                    if(!rejectIt){
                        resolve({
                            resolveData: 'resolve it at '+doneTime
                        });
                    }else{
                        reject({
                            rejectData: 'reject it at '+doneTime
                        });
                    }
                }, 500);
            });
        }
    }
    
    angular.module('app',[])
    .controller('MainCtrl', MainCtrl);

    Read More: http://jsbin.com/jetoyo/4/edit?html,js,output

  • 相关阅读:
    veil-evasion免杀处理
    对程序"加料"
    堆栈溢出
    ICMP隧道 ptunnle
    socat流量操控
    DNS隧道 iodns
    dns隧道 dns2tcpd
    ssh X协议转发
    ssh动态端口转发
    ssh远程端口转发
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4096127.html
Copyright © 2020-2023  润新知