dimanche 26 juillet 2015

Provide url value externally to angularjs file from external config file

I am new to Web development and so to angularjs.I am trying to implement it in my app. This app consumes REST services to fetch and display data.

Following is my code, which is working fine.

JS:

angular.module('myapp', [])
    .controller('oneAppCtrl', function($scope,$http){
        $scope.documentValue = {};

    $http({method: 'GET',
            url: 'http://localhost:70/DocumentRESTService.svc/GetDocuments/'              
           })
        .success(function(data){ alert('Success!');$scope.documentValue=data;})
        .error(function(data){ alert('Error!');$scope.documentValue=data;})
        .catch(function(data){ alert('Catch!');$scope.documentValue=data;});

    $http.get("http://ift.tt/1aaNO8P")
        .success(function(response) {$scope.names = response.records;});
    });

Here as you see I have made two service calls.

My question is , in real life application i wouldn't want these url's to be hardcoded in my app. Instead i would want to keep these url's in some file (call it config file) and read it from there in real time.

I tried to search for this on google and SO but not really sure what exact terminology should i use to search the same.

Any guidance/references would be much appreciated.




Aucun commentaire:

Enregistrer un commentaire