angular的http服务的常用方式

来源:互联网 发布:在数据库表中设置null 编辑:程序博客网 时间:2024/05/17 22:57

在实际中的http服务的使用方法,特别注意服务中返回的对象!!!!!

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>http在service中使用</title><script src="day2/src/angular.js"></script></head><body ng-app="app"><div ng-controller="fristController"></div><script type="text/javascript">var app = angular.module('app',[]);app.service('mySerivce',function($http){// 特别注意的是这里返回的对象!!!!!!this.getData = function(){return $http.get('test.json');}})app.controller('fristController',['$scope','$http','mySerivce',function($scope,$http,mySerivce){mySerivce.getData().success(function(data){console.log(data);}).error(function(data){console.log(data);})}])</script></body></html>


0 0
原创粉丝点击