我正在基于angularjs构建一个Web应用程序。因此,我构建了一个搜索结果UI,该UI在搜索时将结果显示在网格中。现在,当用户单击结果的每一行时,应使用值调用外部网页从单击的网格行传递到外部网页的列数。
我该怎么做,请问有一个示例控制器可供参考。
请帮助
谢谢, 亚历克斯
答案 0 :(得分:1)
如果我对您的理解正确,那么当用户单击某个元素时,您希望将AJAX调用发送给某些JSON API。这是在angularjs控制器中执行此操作的基本操作:
angular.module("your.app")
.controller("ajaxingCtrl",["$http","$scope", function($http, $scope){
$scope.onSomeUserAction = function(argument){
//substitute the type of request your api requires
$http.get("http://your.remote.api/some/resource",
{
//params will get parsed into HTTP query parameters
params: {
x:arguments.x
}
}
).then(function(result){
console.log(result);// and then do what you will with the result
})
}
}])
您可以在angular's $http service docs中找到有关进行ajax调用的更多信息。