【发布时间】:2017-07-30 23:39:25
【问题描述】:
我在Angular2中写了如下代码:
add-item.component.ts
@Component({
selector: 'add-item',
template: `<form-item [title]="abcde"></form-item>`,
})
export class AddItemComponent {
forms: Object[]
constructor() {
this.forms = [{title: 'a', link: 'b'}];
}
}
form-item.component.ts
@Component({
selector: 'form-item',
template: `<h3>{{title}}</h3>`,
inputs: ['title'],
styles: [`
h3 {
color: blue;
}
`]
})
export class FormItemComponent{
@Input()
title: string;
constructor(title: string) {
this.title = title;
}
}
当我运行这段代码时,我得到一个错误:
错误:./AddItemComponent 类 AddItemComponent 中的错误 - 内联 模板:8:0 原因:没有 String 的提供者!
我做了一个小研究,但我不明白问题出在哪里。我也看过这里: Angular2 EXCEPTION No provider for String
你能帮帮我吗?
【问题讨论】:
-
看看这篇文章在 MSDN msdn.microsoft.com/en-us/magazine/mt795191
标签: angular