How can I detect failure to load an image in Elm
问题 How can I detect that an image was failed to be load in Elm? I use img [ src "/path/to/image" ] and would like to know if the image failed to load. In plan old JavaScript I would register to onError event of img but I don't see onError in Elm. 回答1: You can use Html.Events.on to capture an image load error. You will need a Msg value to indicate that the image failed. Here I'll call that ImageError : img [ src "/path/to/image", on "error" (Json.Decode.succeed ImageError) ] [] The use of Json