【发布时间】:2020-06-12 06:26:45
【问题描述】:
国家级.ts
export class CountryClass {
name: string;
states: string[];
cities: string[];
}
这是我创建的类。 但现在我无法在其他组件中使用。
这是
组件:主页.component.ts
import { Component, OnInit } from '@angular/core';
import {CountryClass} from '../country-class';
@Component({
selector: 'app-home-page',
templateUrl: './home-page.component.html',
styleUrls: ['./home-page.component.css']
})
export class HomePageComponent implements OnInit {
countryString:CountryClass[] [
{ 'name' :"India",
statename :['Odish','WestBengal'],
cities:['Bhubaneswar','Kolkata'];}
]
constructor(private country:CountryClass) { }
ngOnInit() {
}
}
在此组件中使用类的属性时遇到错误。也许我遗漏了一些东西。 我得到的错误是:
provide your error here
我在 1 年后使用 angular,但我猜几乎忘记了它的基本知识,甚至找不到任何正确的答案。 如果有人能帮我解决这个问题,那就太好了。
【问题讨论】:
-
你遇到了什么错误?
-
另外 - 您是否直接从您的代码中复制了这个?因为有几个格式问题。你可以在 stackblitz 中重新创建吗?
-
@KurtHamilton stackblitz.com/edit/angular-4rmbsy
-
@KurtHamilton app.component.ts 有代码并检查类的模型文件夹。
-
@KurtHamilton stackBlitz 没有显示错误,但我的 vscode 显示了。
标签: angular typescript class components angular-components