Categories
Mastering Development

angular way to change image src?

<div class="float-right">

  <span class="language dashboard" data-toggle="dropdown">
    <img class="current" src="us-flag.png" />
  </span>

  <div class="dropdown dashboard">
    <a href="javascript:" (click)="setch('en');" class="dropdown-item">
      <img src="us-flag.png" alt="" />english </a
    >
    <a href="javascript:" (click)="setch('it');" class="dropdown-item">
      <img src="it-flag.png" alt="" />italian </a
    >
  </div>

</div>

this the jquery way:

$('.dropdown-item').on({
    'click': function(){
    //do other thing
        $('.current').attr('src','it-flag.png');
    }
});

am using angular 6
looking to write it in angular way without using jquery, however not familiar with it..

looking to load the logic at

  ngOnInit() {

     //assign from default database language setting
     var dbflag = "it";
     //assign $('.current').attr('src','it-flag.png');

  }

  setch(){
    //change flag class="current"
 }

any idea guys, for writing it in angular ts way?

Leave a Reply

Your email address will not be published. Required fields are marked *