Javascript 如何将location.path与angularjs而不是$http.get一起使用
嗨,我正在开发angularjs应用程序。这实际上嵌入到joomla中 满足json响应的URL根据单击的菜单项不断更改。例如:Javascript 如何将location.path与angularjs而不是$http.get一起使用,javascript,php,angularjs,joomla3.0,joomla-component,Javascript,Php,Angularjs,Joomla3.0,Joomla Component,嗨,我正在开发angularjs应用程序。这实际上嵌入到joomla中 满足json响应的URL根据单击的菜单项不断更改。例如: http://localhost/testsite/index.php/good?format=raw http://localhost/testsite/index.php/bad?format=raw http://localhost/testsite/index.php/ugly?format=raw 是否有一种方法可以使用location.path而不是硬编
http://localhost/testsite/index.php/good?format=raw
http://localhost/testsite/index.php/bad?format=raw
http://localhost/testsite/index.php/ugly?format=raw
是否有一种方法可以使用location.path而不是硬编码URL
我的控制器如下:
var app = angular.module('myApp', ['ui.bootstrap']);
app.filter('startFrom', function() {
return function(input, start) {
if(input) {
start = +start; //parse to int
return input.slice(start);
}
return [];
}
});
app.controller('customersCrtl', function ($scope, $http, $timeout) {
$http.get('http://localhost/testsite/index.php/good?format=raw').success(function(data){
$scope.list = data[0]; //before the code was $scope.list = data; The second response with [[that doesn't work is an array with an array inside of it.
$scope.currentPage = 1; //current page
$scope.entryLimit = 10; //max no of items to display in a page
$scope.filteredItems = $scope.list.length; //Initially for no filter
$scope.totalItems = $scope.list.length;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.sort_by = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = !$scope.reverse;
};
});
希望您能提供帮助。我确实通过使用
window.location.pathname+"\?format=raw"
基本上在joomla中,我为同一个组件创建了多个菜单项
例如,显示伦敦的所有酒店。我从component创建一个菜单项并选择london。该组件生成一条json消息,但为了将其用于angularjs,我必须提供json的url,以便AngularController可以获取json
因此,在这种情况下,url必须是
但是,要有多个菜单项,我必须为每个城市创建多个角度控制器,该控制器超过组件的点,并且只有一个控制器
所以我在angularjs的http.get中使用了window.location.pathname+\?format=raw,这确实解决了这个问题
我不确定是否有更好的方法,但我愿意听取建议
希望这能为其他人解决问题
问候,,
贾伊