简体   繁体   English

未捕获(承诺):类型错误:无法读取 angular2+ 中未定义的属性“get”

[英]Uncaught (in promise): TypeError: Cannot read property 'get' of undefined in angular2+

I have made a component in the angular2+ file.我在 angular2+ 文件中创建了一个组件。 I want to make an http request to the nodeJs server.我想向 nodeJs 服务器发出 http 请求。 However, i keep getting - >但是,我不断得到 - >

Uncaught (in promise): TypeError: Cannot read property 'get' of undefined
TypeError: Cannot read property 'get' of undefined

不明确的

To note, I am even unable to retrieve the value of the global variables stored in one function and (unable to) accessed in another function.请注意,我什至无法检索存储在一个函数中并且(无法)在另一个函数中访问的全局变量的值。 And this is the first time i am facing it ever.这是我第一次面对它。

code -代码 -

app.component.ts app.component.ts

import { HttpClient, HttpParams, HttpRequest, HttpEvent } from '@angular/common/http';

@Injectable()
export class MachineMergerComponent implements OnInit {

    constructor(private http: HttpClient) {}

    onFileLoadTopFive(fileLoadedEvent) {

        // -----===================  Top Five Neovis  ==================== -------------

        this.rhsNameTopFive = [];
        this.relationshipInfo = [];

        for (var i = 0; i < 5; i++) {

            this.rhsNameTopFive.push(this.objectValueAfterConfidence1[i].rhs[0])

            console.log("this.rhsNameTopFive = ", this.rhsNameTopFive)

            // http request

            var relationObj = {
                'relationObj1': this.rhsNameTopFive[i]
            }

        }
        console.log("relationObj = ", relationObj);


        this.http.get("http://localhost:3003/seekRelationship?relationObj=" + this.rhsNameTopFive[0])
            .map(Response => Response)
            .catch((err) => {
                console.log("err =", err)
                return Observable.throw(err);

            })
            .subscribe((res: Response) => {

                console.log("XXXXXXXXXXXX Response on /seekExtraction", res);

                this.relationshipInfo[i] = res;

                console.log(" this.relationshipInfo[" + i + "]", this.relationshipInfo[i])
            })
    }

}

app.module.ts app.module.ts

import { HttpClientModule } from '@angular/common/http';

@NgModule({
  imports: [
    CommonModule,

    FormsModule,
    // HttpModule ,

    HttpClientModule,

  ],
  declarations: [   MachineMergerComponent,  ]
})
export class ApiSequenceModule { }

MachineMergerComponent is a service. MachineMergerComponent 是一项服务。 add it under provider list.将其添加到提供商列表下。 (also consider renaming it to MachineMergerService ) (也可以考虑将其重命名为 MachineMergerService )

declarations: [  ... ],
providers:    [ MachineMergerComponent ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2 Uncaught(承诺):TypeError:无法读取未定义的属性'isActivated' - Angular 2 Uncaught (in promise): TypeError: Cannot read property 'isActivated' of undefined 未捕获(承诺):类型错误:无法读取角度 10 中未定义的属性“ɵcmp” - Uncaught (in promise): TypeError: Cannot read property 'ɵcmp' of undefined in angular 10 Angular 2-未捕获(承诺):TypeError:无法读取未定义的属性“ title” - Angular 2 - Uncaught (in promise): TypeError: Cannot read property 'title' of undefined Angular2 +“无法读取未定义的属性X” - Angular2+ “Cannot Read Property X of undefined” 错误错误:未捕获(承诺):TypeError:无法读取Angular 7和rxjx中未定义的属性“ length” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined in Angular 7 and rxjx 未捕获(承诺):类型错误:无法读取 ionic 2 应用程序中未定义的属性“应用” - Uncaught (in promise): TypeError: Cannot read property 'apply' of undefined in ionic 2 app 未捕获(承诺):TypeError:无法读取未定义的属性&#39;includes&#39; - Uncaught (in promise): TypeError: Cannot read property 'includes' of undefined 未捕获(承诺):TypeError:无法读取未定义的属性“ executeSql” - Uncaught (in promise): TypeError: Cannot read property 'executeSql' of undefined 未捕获(承诺):TypeError:无法读取未定义的属性“替换” - Uncaught (in promise): TypeError: Cannot read property 'replace' of undefined 错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“id” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'id' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM