调用 img src 的函数 onerror
calling a function onerror of img src
这是我在 angular 2:
中的代码
test.component.html:
<img src="./assets/sample.jpeg" onError="setValue()">
{{imageMenu}}
test.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
imageMenu:boolean = true;
constructor() { }
ngOnInit() {
}
setValue():void{
alert("hi");
this.imageMenu = !this.imageMenu;
}
}
我的问题是当图像源为空时,布尔值仍然为真。 setValue()
不会因错误而被调用。请大家帮我解决这个问题。我是 angular.
的新手
当您在 Angular 中使用 HTML DOM 事件时,请从事件中删除 on
前缀并使用它。前
onclick
---> (click)
使用(error)
代替onError
<img src="assets/sample.jpeg" (error)="setValue()">
这是我在 angular 2:
中的代码test.component.html:
<img src="./assets/sample.jpeg" onError="setValue()">
{{imageMenu}}
test.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
imageMenu:boolean = true;
constructor() { }
ngOnInit() {
}
setValue():void{
alert("hi");
this.imageMenu = !this.imageMenu;
}
}
我的问题是当图像源为空时,布尔值仍然为真。 setValue()
不会因错误而被调用。请大家帮我解决这个问题。我是 angular.
当您在 Angular 中使用 HTML DOM 事件时,请从事件中删除 on
前缀并使用它。前
onclick
---> (click)
使用(error)
代替onError
<img src="assets/sample.jpeg" (error)="setValue()">