admin管理员组文章数量:1353317
I am recenbly new to NgRx Signal Store. and I have a question around how (if possible) to enable intellisense and type detection on the signal store class in HTML.
// job.store.ts - here I defined a JobRole Signal Store
import { signalStore, withState, withMethods, patchState } from '@ngrx/signals';
export interface JobRole {
name:string,
levels: string[]
}
type JobRoleState = {
jobRoles: JobRole[];
isLoading: boolean;
error: string | null
};
const initialState: JobRoleState = {
jobRoles: [{name: "Data Scientist", levels: ['1','2']}],
isLoading: false,
error: null
};
export const JobRoleStore = signalStore(
{
providedIn:'root'
},
withState(initialState),
withMethods((store)=> ({
loadAll(){
patchState(store, {jobRoles: [{name: "Full Stack Dev", levels: ['1','2','3']}]})
}
})),
);
What is working:
The following implemention of using signal from previously defined signal store worked fine. Especially the intellisense and type detection is working properly. See screenshot below.
@Component({
imports: [
RouterModule,
JsonPipe,
AsyncPipe,
],
standalone: true,
selector: 'app-root',
template: `
<div>
{{ jobRoles[0].name }}
</div>
`,
styleUrl: './appponent.scss',
})
export class AppComponent {
jobRoles: JobRole[] = []
jobRoleStore = inject(JobRoleStore)
constructor() {
effect(() => {
// assign the emitted jobRoles value from signal store to local variable.
this.jobRoles = this.jobRoleStore.jobRoles()
});
}
}
Example where intellisense and type detection worked fine
What is Not working:
The following implemention of using signal from previously defined signal store worked fine. However, both intellisense and type detection is not working properly. See screenshot below.
@Component({
imports: [
RouterModule,
JsonPipe,
AsyncPipe,
],
standalone: true,
selector: 'app-root',
template: `
<div>
{{ this.jobRoleStore.jobRoles()[0].name }}
</div>
`,
styleUrl: './appponent.scss',
})
export class AppComponent {
jobRoleStore = inject(JobRoleStore)
constructor() {
}
}
Unable to detect jobRoleStore type in html Able to detect jobRoleStore type in typescript Example where intellisense and type detection isn't worked fine
I would like to get some help explain why type detection failed when direct usage of signal store class in html. As well as looking for potential solution to enable type detection of signal store class in html.
版权声明:本文标题:angular - NgRx Signal Store intellisense and type detection isn't working when use in HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743915852a2561200.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论