相关疑难解决方法(0)

类型'对象'上不存在属性''.可观察的订阅

我刚刚开始使用Angular2,我遇到了一个我无法理解的问题.

我有一些这样的模拟数据:

export const WORKFLOW_DATA: Object =
{
    "testDataArray" : [
        { key: "1",              name: "Don Meow",   source: "cat1.png" },
        { key: "2", parent: "1", name: "Roquefort",    source: "cat2.png" },
        { key: "3", parent: "1", name: "Toulouse",   source: "cat3.png" },
        { key: "4", parent: "3", name: "Peppo", source: "cat4.png" },
        { key: "5", parent: "3", name: "Alonzo",     source: "cat5.png" },
        { key: "6", parent: "2", name: "Berlioz", source: "cat6.png" }
    ]
};
Run Code Online (Sandbox Code Playgroud)

然后将其导入服务并"观察"

import { Injectable } from '@angular/core';

import …
Run Code Online (Sandbox Code Playgroud)

observable rxjs typescript angular

16
推荐指数
3
解决办法
3万
查看次数

如何修复'属性不存在类型'错误?

我正在关注这个视频教程(相同的文本版本).我遵循完全相同的代码,我收到此错误:

错误TS2339:类型'EmployeeService'上不存在属性'getEmployees'

我看着在互联网上,堆栈溢出走访了许多问题,如这个,这个,这个这个,和许多其他人的问题打开相关GitHub上此错误.

服务:

//import statements go here ...

@Injectable()
export class EmployeeService {
private listEmployees: Employee[] = [
    {
      //just to avoid longer code, deleted dummy data.
    },
  ];

  getEmployees(): Employee[] {
      return this.listEmployees; //ERROR in src/app/employees/list-employees.component.ts(14,44)
  }
}
Run Code Online (Sandbox Code Playgroud)

组件类:

//import statements
@Component({
    selector: 'app-list-employees',
    templateUrl: './list-employees.component.html',
    styleUrls: ['./list-employees.component.css']
})
export class ListEmployeesComponent implements OnInit {
    employees: Employee[];
    constructor(private _EmployeeService: EmployeeService) { }

    ngOnInit() {
        this.employees = …
Run Code Online (Sandbox Code Playgroud)

typescript angular

13
推荐指数
1
解决办法
3万
查看次数

标签 统计

angular ×2

typescript ×2

observable ×1

rxjs ×1