3

My question is about making src in html script tag dynamic. Now, I have something like this at the bottom of the html :

<script src="https://blabla.com/assets/jxx.js"></script>

In my angular js file, I've a method to return the url prefix dynamically.

$scope.trustSrc = function(src) {
    return $sce.trustAsResourceUrl($scope.pathPrefix + src);        
};

And what I want to do is transform the src part to this:

<script type="text/javascript" src="{{trustSrc('/assets/jxx.js')}}"></script>

The prefix of the url changes depending on the environment. So I need to change it dynamically.

This method works if I put the script tag in the html's head portion. But mine should be outside of the head and at the bottom of the html.

What do you recommend to do this?

4

1 Answer 1

0

I'm not sure but it can be happening because of your controller's scope.

As you are using trustSrcfunction with $scopein your controller, make sure that in HTML file you are using <script></script> in controller's scope.

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

1 Comment

I'm using it with $scope as above. The problem is if I put that last line in html head portion it works , but in the body portion it is not working. What should I do to make it work in html body, that is my question actually.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.