I am trying to bind the src
attribute of an HTML <script>
element to a variable in my angular controller, so that I can update it from controller without dealing with any UI.
So far I've tried all these options:
<script type="text/javascript" ng-src="{{sourceUrl}}"></script>
<script type="text/javascript" src="{{sourceUrl}}"></script>
<script type="text/javascript" ng-src="sourceUrl"></script>
In my controller I have:
$scope.sourceUrl = "https://<some url goes here>";
When running the page in the browser after the $scope.sourceUrl gets set there is no outgoing request to sourceUrl, so I am sure I am doing something wrong. Any ideas?
I found several posts about src
attribute of <img>
element, and ng-src
should work as they say, but I guess <script>
is somehow different.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…