我正在尝试从Web服务获取数据。这是我的代码。
$scope.savePricing = function(){
var pricing = {
"PricingSchemeId": 0,
"Name": $scope.name,
"LastUserName": "Tan",
"LastModifiedDate": "",
"IsActive": true,
"CurrencyId": $scope.selectedCurrency.CurrencyId,
}
$http({
url: config.addPricing,
data: pricing,
method: "POST"
}).success(function(data){
alert("Success");
}).error(function(data){
alert("Failed");
});
})
但是当我运行此功能时,会显示以下错误:
我现在能做什么?
答案 0 :(得分:0)
config.addPricing
未定义。我可以轻松地重现该错误如下:
index.html
:
<!DOCTYPE html>
<html ng-app="Foo">
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<script src="my-angular.js"></script>
</head>
<body ng-controller="SomeCtrl">
<button ng-click="go()">Go</button>
</body>
</html>
my-angular.js
:
var app = angular.module("Foo", []);
app.controller("SomeCtrl", function($scope, $http) {
var config = {}; // Note the lack of "url" field.
$scope.go = function() {
$http({
url: config.url, // undefined
data: {},
method: "POST"
}).success(function(data) {
console.log("Success: data", data);
}).error(function(data) {
console.log("Error: data", data);
});
};
});