0

I currently have the following link on my page.

<a href="/#!/blog/{{article.id}}" title="Permalink to {{article.title.__cdata}}" itemprop="url">{{article.title.__cdata}}</a> 

I would like to make a small change, but am not sure of the proper syntax.

If {{article.url}} is NOT zero-length, I would like to use that instead of /#!/blog/{{article.id}}

If {{article.url}} is zero-length, I would like to continue to use /#!/blog/{{article.id}}

1 Answer 1

1
<a ng-href="{{ article.url || '/#!/blog/' + article.id }}" ...>

or you could put this logic in the controller if you find it too complex to be in the view:

<a ng-href="{{ getPermalink(article) }}" ...>

$scope.getPermalink = function(article) {
    return article.url || '#!/blog/' + article.id;
}
Sign up to request clarification or add additional context in comments.

Comments

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.