0

Controller Code

myApp.controller("BaseController", ["$scope", function($scope) {
        $scope.imgProcessingUrl = appUrl + "Images/ajax-loader.gif";
    }
]);

here appUrl is http://localhost/sample/public/

Html Code

<img id="imgProcessing" ng-src="{{imgProcessingUrl}}" style="display:none;">

master.blade.php

<script>
    var appUrl = "{!! URL(''); !!}/";
</script>

Problem is: webpage always shows the rendered html like below.

<img id="imgProcessing" style="display:none;">

Am i missing something?

2
  • how and where are you defining appUrl? Commented Dec 14, 2016 at 21:38
  • Can you post the entire html? Commented Dec 14, 2016 at 21:44

1 Answer 1

1

To make global variables available inside the controllers scope you must pass in the browsers $window object as a dependency.

myApp.controller("BaseController", ["$scope", "$window", function($scope, $window) {
        $scope.imgProcessingUrl = $window.appUrl + "Images/ajax-loader.gif";
    }
]);

Sign up to request clarification or add additional context in comments.

4 Comments

This is not 100% true in my case because I have no difficulty in getting value from appUrl without $window
@PankajGarg So can you console.log(appUrl) from with in the controller?
I already mentioned the value in my question. I have no problem in fetching the appUrl value :)
@PankajGarg So if you inject the $window service as I mentioned in my answer are saying that this solution doesn't work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.