我正在学习 Redux,我正在尝试使用 ng2-redux 在 Angular 7 中实现它。我在 npm 页面上看到它已被弃用,因此我使用建议的npm install @angular-redux/store'. 我配置了我的 app.module,它给了我这个错误:error TS2307: Cannot find module 'redux'.我导入错了,可能是什么原因造成的?我尝试在互联网上搜索,但没有找到任何东西。这是我的app.module文件:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgRedux, NgReduxModule } from '@angular-redux/store'
import { rootReducer, AppState } from '../app/store';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(ngRedux: NgRedux<AppState>) {
ngRedux.configureStore(rootReducer, {});
} …Run Code Online (Sandbox Code Playgroud) 我正在编写一个简单的JavaScript游戏,其中用户点击播放声音的div,如果他们猜测动物声音是正确的,则计数器会跟踪他们的分数和增量.
它可以工作,但如果再次播放相同的声音并且用户猜测它会使计数器增加两个而不是一个,有时甚至三个,我无法弄清楚为什么以及如何修复它,这是我的HTML:
<div id="counter">Score:<span id="counter-score"> 0</span> </div>
Run Code Online (Sandbox Code Playgroud)
这是JavaScript代码:
var sounds = [
{
animalType: 'horse',
sound: new Audio('../sounds/Horse-neigh.mp3')
},
{
animalType: 'bear',
sound: new Audio('../sounds/grizzlybear.mp3')
},
{
animalType: 'goat',
sound: new Audio('../sounds/Goat-noise.mp3'),
}
];
var player = document.getElementById('player');
var enteredWord = document.getElementById('entered-word');
var counter = document.getElementById('counter-score');
startGame();
function startGame() {
player.addEventListener('click', function() {
var sound = sounds[Math.floor(Math.random() * sounds.length)];
var currentSound = sound.animalType;
sound['sound'].play();
enteredWord.addEventListener('keydown', function() {
if (event.key === 'Enter') {
if (enteredWord.value === currentSound) {
counter.textContent++;
}
} …Run Code Online (Sandbox Code Playgroud)