这个简化的组件调度一个操作来将数据保存到存储中:
import { Store } from '@ngxs/store';
import { ViewLogin } from '../actions/login.actions';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent {
constructor(private store: Store) {}
onSignInClick(login: string) {
this.store.dispatch(new ViewLogin({ login }));
}
}
它总是带来错误NullInjectorError: No provider for Store!
。
奇怪的是,我在应用程序的另一个组件中有相同的代码,而且它工作没有任何问题!
任何想法?