在angularjs 2中获取一个错误
问题描述:
我想在angularjs2中使用reddit应用程序。在angularjs 2中获取一个错误
得到一个错误:d:/角2/SimpleReddit/src目录/应用/组件/书签交易/ reddit.component.ts(9,13):找不到名称 '文章'
这是我的文件夹结构
Reddit.component.ts
任何一个可以帮助我在此?
答
首先,你必须输入你想使用
import { Articles } from '../articles'; // Make sure the path is according to what you have in the project structure
类
根据您的项目结构,看起来您没有名为Articles
的课程。 一条建议,命名类而不是Articles
时,将其命名为Article
。最好使用单数形式。因此,9号线将看起来像:
articles: Article[];
所以,你可能需要做的是你叫article.ts
和export class Article { // your properties }
Article
目录下创建一个新的文件,并将其包含在上面的例子。
答
您还没有将类文章导入到组件中,没有它,typescript编译器不能为此变量输入类型。
添加import语句导入类:
import { Articles } from './articles';
调整路径文章相应文件
我应该提供完整的路径像导入{文章}从'./app/component/Article/article.component'; – JMR
这是正确的吗? – JMR
'从'../ Article/article.component'中导入{Articles};'如果您在Reddit.component.ts'文件中使用它,就应该足够了 – moonflare