Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于静音HTML音频的Typescript函数_Javascript_Html_Angular_Typescript_Audio - Fatal编程技术网

Javascript 用于静音HTML音频的Typescript函数

Javascript 用于静音HTML音频的Typescript函数,javascript,html,angular,typescript,audio,Javascript,Html,Angular,Typescript,Audio,我有在屏幕加载时自动播放的音频。我试图包括一个按钮,将静音的音频使用打字脚本。该应用程序内置于Angular4。我试过使用 document.getElementById('mute').addEventListener('click', function (e) { e = e || window.event; audio.muted = !audio.muted; e.preventDefault(); }, false); 但是am get事件没有分配给MouseEvent,它还表示mu

我有在屏幕加载时自动播放的音频。我试图包括一个按钮,将静音的音频使用打字脚本。该应用程序内置于Angular4。我试过使用

document.getElementById('mute').addEventListener('click', function (e)
{
e = e || window.event;
audio.muted = !audio.muted;
e.preventDefault();
}, false);
但是am get
事件没有分配给MouseEvent
,它还表示
muted
在type
HTMLElement
上不存在


main.ts
文件中是否有这样做的方法?

HTMLMEDIALEMENT
界面上存在
muted
属性。您必须使用类型断言来断言
audio
的类型为
htmlmediaoelement
类型

let audio = document.getElementById('your-audio-element') as HTMLMediaElement
// ...
audio.muted = true;