1

I have an angularJS component and I manually set the url for a link. But I want to change this url after blogposts is loaded in a different method.

HTML:

<a ng-href="{{ $ctrl.readMoreUrl }}" id="readMore" class="read-more" translate="READ_THE_POST" >
READ MORE ON THE BLOG<img src="../../images/assets/arrow-right.svg" 
class="img-responsive arrow-right" alt=""/></a>

Javascript:

function BlogDetailController() {
    var ctrl = this;
    ctrl.readMoreUrl = 'https://mytest-site.com/blogpost/superpost/';
}

    var angularApp = angular.module(

    .component('postDetail', {
        templateUrl: '/javascripts/controllers/blogDetail.html',
        controller: BlogDetailController,
        bindings: {post: '=', indx: '=', title: '='}
    })

And I want to change it in a different function:

$scope.loadpost = function () {
    //I want to change the url here
}

I tried to add a simple eventlistener to the "readMore"s id. But sometimes it works and sometimes it is not... And I think this is not the best way to change the url. So my question is, how can I change the url, whenever I want, after the component started to use the controller?

1 Answer 1

0

Have you tried connecting the img source with ng-src? https://www.aspsnippets.com/Articles/Dynamically-change-SRC-of-Image-in-AngularJS.aspx

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

1 Comment

I tried something similar, but doesn't work. I want to change the url of a link, so ng-src is not good for me.

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.