我有一个名为product的AngularJS指令。每当我单击该指令中的一个按钮时,我就需要执行一个操作,该按钮涉及向我的服务器发出$http.get请求并对响应进行工作。我有一个文件看起来很好,直到它真正开始发出请求,这时,Fiddler中显示的url与我试图提出请求的内容不匹配,我不知道为什么。
如下面所示,请求应该是访问我的域/ api /product/GetToken api服务,但在Fiddler中,我将显示为“/user/object%20 object”,我不知道这是为什么。而且,控制台不会产生错误。
以下是有关的指令:
angular.module('myApp').directive('product', function($location) {
return {
restrict: 'E',
replace: false,
templateUrl: 'path/to/template.html',
scope: {},
controller: function($scope, $state, $cookieStore, $http) {
$scope.productClick = function(key) {
var url = 'http://exampleurl.com/api/product/GetToken';
$http.get({url:url})
.success(d, s, h, c) {
$state.go('this.someplace');
}
.error(function(d, s, h, c) {
$state.go('this.otherview');
});
},
link: function($scope, e, a, m) {
$scope.name = a.name + "123";
}
}
}
}有没有人知道我能做什么,而我在这里抓不到?
发布于 2014-06-23 12:54:04
使用$http和$http.get略有不同。只要使用$http,您就可以按照您编写的(发送配置对象)进行操作,但是使用$http.get (或post等),您可以将url作为字符串传递。这就是:
$http.get('/my/url/').success(...).error(...);或
$http.post('/my/url/', dataObject).success(...).error(...);或者只有$http
$http({url: '/my/url', method: 'GET'}).success(...).error(...);https://stackoverflow.com/questions/24366015
复制相似问题