嗨,我尝试后与AnguarJs数据,但有一些issues.My js代码无法发布低于:采用了棱角分明JS
var app = angular.module('myApp', []);
app.constant('appUrl', 'http://localhost/zara/rest/');
/*---- categories fetch code -------*/
app.controller('myController',['$scope','$http','appUrl', function($scope, $http , appUrl) {
$scope.newName = "";
$scope.postForm = function() {
var data = $.param({
name: $scope.newName
});
$http.post("http://localhost/zara/rest/api_customerlogin.php", data).success(function(data, status) {
$scope.hello = data;
console.log(data);
});
};
}]);
我收到此错误TypeError: Cannot read property 'param' of undefined
当我改变代码赞一个然后我得到这个错误。
<script>
angular.module('myApp', [])
.controller('myController', ['$scope', '$http', function($scope, $http) {
this.loginForm = function() {
var user_data='user_email=' +this.inputData.email+'&user_password='+this.inputData.password;
$http({
method: 'POST',
url: 'login.php',
data: user_data,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
console.log(data);
})
}
}]);
</script>
不能张贴到login.html的page.This是我在AnguarJs第一个项目这样不是很familer与this.Thanks。
你有没有尝试在服务文件:app.serivce(“服务”,[$ HTTP,函数(){}]) – amrography
不,我刚试过的代码与上述codes.How将服务工作与此? –
什么是'$ .param'为你做什么?!,将你的数据更改为'object'作为'var data = {name:$ scope.newName}' – Maher