Hi I am working on a angularjs app. This is actually embedded in to joomla.
The URL that caters the json responses keeps changing based on the menu item clicked. For example:
http://localhost/testsite/index.php/good?format=raw
http://localhost/testsite/index.php/bad?format=raw
http://localhost/testsite/index.php/ugly?format=raw
Is there a way I can use location.path instead of hardcoding a URL.
My controller is below:
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;
};
});
hope you can help.
I did resolve this issue by using the
window.location.pathname+"\?format=raw"
Basically In joomla, i have created multiple menu items for a same component.
for example to display all the hotels in london . I create a menu item from component and select london. This component generates a json message but in order to use this with angularjs i have to provide the url for the json so angular controller can get json.
So in this case the url has to be http://test.com/london?format=raw.
But to have multiple menu items i will have to create multiple angular controllers for each city which beats the point of component and only one controller.
so I used window.location.pathname+"\?format=raw" in the http.get of angularjs and this did resolve the issue.
i am not sure if there are any better ways of doing it but am open for suggestions.
hope this resolves the issues for some one else.
Regards, Jai