0

I am writing a simple code to send data to some php file through Angular.js. I hope I am doing everything correctly but still getting error. Can someone help me out?

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);
        }
    }
}]);

My Error:

enter image description here

4

1 回答 1

1

你必须注入$http,

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

你忘了$

于 2015-11-29T15:54:58.153 回答