在Angular-js中使用服务发送数据到php

Using services to send data to php in Angular-js

我正在编写一个简单的代码,通过 Angular.js 将数据发送到某个 php 文件。我希望我做的一切都正确但仍然出错。有人可以帮我吗?

Index.html

<html>
<head>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script src="angularScript.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl"> 
<form> 
Name: <input type="text" data-ng-model="name"/>
<button data-ng-click="ok()">Click</button>
</form> 
</body> 
</html>

angularScript.js

//1. App Declaration
var app = angular.module('myApp',[]);

//2. Controllers
app.controller('myCtrl',function($scope, myServices){
    $scope.name = '';
    $scope.ok = function(){
        myServices.ok($scope.name);
    }
 });

//3. Services
app.service('myServices',['http',function($http){
    return {
        ok: function(data) {
            var ok = {
                method: 'POST',
                //url: '',
                headers: {
                    'Content-Type': 'application/json'
                },
                data: {
                    Name: data
                }
            };
            return $http(ok);
        }
    }
}]);

我的错误:

你必须注入 $http,

app.service('myServices',['$http',函数($http){ ...

你忘记了 $