码迷,mamicode.com
首页 > Web开发 > 详细

Angular 学习笔记——$http

时间:2015-12-07 20:25:58      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>
    var m1 = angular.module(‘myApp‘,[]);
    m1.controller(‘may‘,[‘$scope‘,‘$http‘,‘$timeout‘,function ($scope,$http,$timeout){
        var timer = null;
        $scope.change = function (name){
            $timeout.cancel(timer);

            timer = $timeout(function (){
                $http({
                    method:‘JSONP‘,
                    url:‘https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=‘+name+‘&cb=JSON_CALLBACK‘
                }).success(function (data){
                    $scope.data = data.s;
                })
            },500);
        }
    }])
</script>
</head>

<body>
    <div ng-controller=‘may‘>
        <input type=‘text‘ ng-model=‘name‘ ng-keyup="change(name)">
        <input type="button" value="search" ng-click="change(name)">
        <ul>
            <li ng-repeat=‘d in data‘>{{d}}</li>
        </ul>
    </div>

</body>
</html>

 

Angular 学习笔记——$http

标签:

原文地址:http://www.cnblogs.com/mayufo/p/5027112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!