为了账号安全,请及时绑定邮箱和手机立即绑定

angular2中怎么请求数据

angular2中怎么请求数据

一只名叫tom的猫 2019-05-16 10:10:51
angular2中怎么请求数据
查看完整描述

2 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

AngularJS提供$http控制,可以作为一项服务从服务器读取数据。服务器可以使一个数据库调用来获取记录。 AngularJS需要JSON格式的数据。一旦数据准备好,$http可以用以下面的方式从服务器得到数据。
function studentController($scope,$http) {
var url="data.txt";
$http.get(url).success( function(response) {
$scope.students = response;
});


查看完整回答
反对 回复 2019-05-17
?
喵喵时光机

TA贡献1846条经验 获得超7个赞

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<html>

<head>

<title>AngularJs Demo</title>

<script type='text/javascript' src="./angular.min.js"></script>

</head>

<body ng-app="myApp">

<h1>AngularJs Demo</h1>

<div ng-cloak ng-controller="DemoCtrl" ng-init="pageInit()">{{hello}}</div>

<script type='text/javascript'>

var app = angular.module('myApp', []);

app.controller('DemoCtrl', function($scope) {

  $scope.pageInit = function() {

    $scope.hello = 'Hello AngularJs';

  }

});

</script>

</body>

</html>

保存为html, 当前目录需要angular.min.js文件.

 




查看完整回答
反对 回复 2019-05-17
  • 2 回答
  • 0 关注
  • 486 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信