【发布时间】:2019-01-09 16:30:25
【问题描述】:
我有一个加载和保存模板的服务,我希望当我点击离子选择时,选项会动态加载,这样每个保存的模板都是一个选项,而不是硬编码的选项。
我尝试使用 NgFor 并创建一个服务实例来处理 JS 文件中的模板。
这是HTML代码
```
<ion-item>
<ion-label>Load template</ion-label>
<ion-select>
<ion-option *ngFor = "let template of templates;">
{{templates}}
</ion-option>
</ion-select>
</ion-item>
```
这是模板服务代码
```
export class TemplateService {
public templates: Template[] = [];
...
getAllTemplates(): Template[] {
return this.templates;
}
```
这是 JS 代码
```
export class NewTransactionPage {
templates: Template[];
...
constructor(public templateServicerino: TemplateService) {
this.templates = this.templateServicerino.getAllTemplates();
```
我收到一条错误消息:“未捕获(承诺中):错误:StaticInjectorError(AppModule)[NewTransactionPage -> TemplateService: StaticInjectorError(Platform:core)[NewTransactionPage -> TemplateService: NullInjectorError: No provider for Template Service!”
【问题讨论】:
-
您的代码中有错字,它是
*ngFor而不是ngfor. -
您似乎忘记在 app.module 中声明 TemplateService,或者可能是 TemplateServices 自己的依赖项之一
标签: javascript angular ionic-framework ionic3