Angular2:无法读取未定义的属性“调用"(引导时) [英] Angular2: Cannot read property 'call' of undefined (when bootstrapping)

查看:90
本文介绍了Angular2:无法读取未定义的属性“调用"(引导时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查底部的更新!

我有一项服务在应用程序引导时引发错误. Cannot read property 'call' of undefined.我正在使用ng2 2.4.2和angular-cli 1.0.0-beta.24.

I have a service that throws an error while the app is bootstrapping. Cannot read property 'call' of undefined. I'm using ng2 2.4.2 and angular-cli 1.0.0-beta.24.

错误

未捕获的TypeError:无法在Object.450(src异步)在webpack_require(bootstrap 81b10f8…:52)在Object.621(environment.ts:8)在webpack_require(bootstrap 81b10f8…:52)处读取未定义的属性调用" :7)在webpack_require(引导程序81b10f8…:52)在Object.1057(util.service.ts:35)在webpack_require(引导程序81b10f8…:52)在webpackJsonpCallback(引导程序81b10f8…:23)在main.bundle.js: 1

Uncaught TypeError: Cannot read property 'call' of undefined at webpack_require (bootstrap 81b10f8…:52) at Object.621 (environment.ts:8) at webpack_require (bootstrap 81b10f8…:52) at Object.450 (src async:7) at webpack_require (bootstrap 81b10f8…:52) at Object.1057 (util.service.ts:35) at webpack_require (bootstrap 81b10f8…:52) at webpackJsonpCallback (bootstrap 81b10f8…:23) at main.bundle.js:1

您可以看到util服务存在问题-如下所示:

As you can see it's a problem with the util service - this looks as follows:

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Project } from '../datatypes/';
import { Response } from '@angular/http';


@Injectable()
export class UtilService {
    constructor(private router: Router) {}

    public redirectToProject(project: Project) {
        let query = project.ProjectName.split(' ')
            .join('-')
            .concat('-' + project.Id)
            .toLowerCase();
        this.router.navigate(['/project', query]);
    }

    public extractData(res: Response) {
        let body = res.json();
        return body || {};
    }
}

奇怪:当检查chrome中的源文件时,它没有语法高亮显示,这表明存在语法错误-我认为没有.

Strange: When inspecting the source file in chrome it has no syntax highlighting, which would suggest a syntax error - in my opinion there's none though.

我更新为ng2.4.4和angular-cli 1.0.0-beta26.问题仍然是一样的. 在玩耍时,Arjan发现它可以与beta 21一起使用.将不得不检查所做的更改.现在,问题不在上面的服务中,而是在environment.ts文件(具有所有默认设置)中.

I updated to ng2.4.4 and angular-cli 1.0.0-beta26. The problem is still the same. While playing around, Arjan found out that it works with beta 21. Will have to check the changes. The problem now isn't in the service above but in the environment.ts file (which has all the defaults).

推荐答案

最后,我找到了答案-适用于beta.32.3.我们必须使用这些文件:

Finally I found the answer - works with beta.32.3. We have to use these files:

<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="scripts.bundle.js"></script>
<script type="text/javascript" src="styles.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>

更新本地软件包也很重要. 其github页面上对全局更新进行了很好的描述. 本地更新也很容易-只需更新package.json中的依赖项即可.

It's also important to update the local and the global package. Updating globally is described well on their github page. Updating locally is easy too - simply update the dependency in your package.json.

重要:由于beta.29 angular cli是软件包 @angular/cli ,因此不再是 angular-cli ..

Important: Since beta.29 angular cli is the package @angular/cli, not angular-cli anymore..

这篇关于Angular2:无法读取未定义的属性“调用"(引导时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆