mercredi 31 mai 2017

Pass php Laravel's APP_URL value to AngularJS

I use AngularJS in my Laravel app.

In AngularJS, I use:

$location.host()

to get the domain of my app (e.g: www.example.com) and get access to my API, e.g:

var url = $location.protocol() + "://" + $location.host() + "/api/products/" ;

Now I changed servers and my main app location went from www.example.com to www.example.com/here. $location.host() gives me www.example.com, but not the /here part.

I am trying to find a way to use Laravel's APP_URL value (which contains my main app location) and pass it to AngularJS:

var app = angular.module("appProducts"); 
app.controller("CtrlUserSchedule", ['$scope', '$http', '$location', '$modal', function($scope, $http, $location, $modal) {

    --> var laravelUrl = ** get php APP_URL value here **;

        var apiUrl = laravelUrl + "/api/products/" ;

What's the cleanest way to pass APP_URL to AngularJS. Is there a way to set it globally so APP_URL is available in all my AngularJS apps?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rapv6K
via IFTTT

Aucun commentaire:

Enregistrer un commentaire