0

I am creating a web app using different technologies.

First I am opening a HTML/PHP file like this http://....filename.php?id=23

At this file I am calling an external JS file, like this:

filename.php piece of code:

<script src="app/appClients.js"></script> 

Here you have the code for appClients.js:

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('ajax/getClientsContacts.php').success(function(data){
        $scope.list = data;
        $scope.currentPage = 1; //current page
        $scope.entryLimit = 5; //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;
    };
});

And at line:

 $http.get('ajax/getClientsContacts.php').success(function(data){

I need to pass the id parameter from the first URL to file getClientsContacts.php, also as id parameter to the URL.

Any help is welcome.

mvasco
  • 4,965
  • 7
  • 59
  • 120
  • @arunpjohny, thank you, but the question that you marked has any accepted answer. – mvasco Oct 15 '15 at 05:39
  • that could be because the OP may not be interested... but there is a highly upvoted answer – Arun P Johny Oct 15 '15 at 05:40
  • @arunpjohny, you are right, but I am not able to see how to apply that answer to my code, if you can't help me, I will try to find a solution by myself, but I guess this is an interesting question that could help other people too. – mvasco Oct 15 '15 at 05:43
  • 1
    you can also try a non angular solution http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – Arun P Johny Oct 15 '15 at 05:51
  • @ArunPJohny, I have found this: http://stackoverflow.com/questions/1017424/pass-vars-to-javascript-via-the-src-attribute Do you think it could work like this? I will try it now... – mvasco Oct 15 '15 at 05:52

1 Answers1

0

Thanks to Pass vars to JavaScript via the SRC attribute I have solved my issue.

This is what I have done at my original file:

<script>
var idrecibida=(variable received from URL param)
</script>
<script src="app/appClients.js"></script>

and then I can use idrecibida where needed. Simple...

Community
  • 1
  • 1
mvasco
  • 4,965
  • 7
  • 59
  • 120