Hatice Sebli
Hatice Sebli

Reputation: 51

How to call angular method in html?

I'm using *ngFor(*ngFor="let radio of items) in div element and inside of this div , using an img element.I am trying to set the src like [src]="radio.getIsActiveIcon()" but "46 ERROR TypeError: _v.context.$implicit.getIsActiveIcon is not a function at Object.eval [as updateRenderer] " error happens. My img element and getIsActiveIcon func is;

<img class="is-active-image" [src]="radio.getIsActiveIcon()">

public getIsActiveIcon(): string {
    if (this.isActive === 1) {
        return 'assets/img/ic_active.png';
    }
    return 'assets/img/ic_not_active.png';
}

Upvotes: 1

Views: 96

Answers (3)

Hatice Sebli
Hatice Sebli

Reputation: 51

Finally,I used Pipe and it works.it's more clear.

Upvotes: 1

Masoud Bimar
Masoud Bimar

Reputation: 7801

Preventing cross-site scripting (XSS) Cross-site scripting (XSS) enables attackers to inject malicious code into web pages. Such code can then, for example, steal user data (in particular, login data) or perform actions to impersonate the user. This is one of the most common attacks on the web.

To block XSS attacks, you must prevent malicious code from entering the DOM (Document Object Model). For example, if attackers can trick you into inserting a tag in the DOM, they can run arbitrary code on your website. The attack isn't limited to tags—many elements and properties in the DOM allow code execution, for example, and . If attacker-controlled data enters the DOM, expect security vulnerabilities.

for more info go here Angular Security

Upvotes: 0

Talg123
Talg123

Reputation: 1506

<img class="is-active-image" [src]="getIsActiveIcon()">

Not sure what does radio means, but all you have to do is call the function.

Upvotes: 0

Related Questions