Explained in a different response, watched expressions are evaluated during each digest cycle and compared to their previous values through dirty checking. If a change is detected, another round of digestion begins as modifications in one value may impact others.
If a circular dependency occurs (even within a single expression), it can lead to an endless loop that Angular handles by stopping after 10 iterations.
In your case, the getLink
function returns a promise (from $http) which isn't synchronously awaited by Angular bindings.
The solution is to initiate the $http
request and assign its result to a ViewModel property in the callback function. This property will then be bound to the <a>
element:
function getLink(){
$http.get(inputUrl)
.success(function(data){
$scope.url = data.data;
});
}
You can trigger getLink
when your controller initializes, for instance.
In the View, simply bind the url
variable to the ng-href
attribute (not href
):
<a ng-href="url">My Link</a>