错误:拒绝访问属性"拒绝"的权限

Par*_*edi 8 angular

错误:拒绝访问属性"拒绝"的权限

当我使用Http Service注入它时抛出错误

import { Injectable }     from '@angular/core';
import { Http, Response } from '@angular/http';


@Injectable()
export class ToDoService{
    constructor (http: Http) {}

    getTODOS():any{       
        return "";
        // return this.http
        //    .get('https://jsonplaceholder.typicode.com/posts')
        //    .map(res => res.json().data);
    }  
}
Run Code Online (Sandbox Code Playgroud)

Grr*_*ang 6

我在Firefox中遇到了同样的例外.请尝试其他浏览器进行调试.

在我的情况下,FireBug只显示"错误:拒绝访问属性的权限"拒绝"",并且没有更多信息.

但在Chrome中,它显示更多内容,例如:

Error: Uncaught (in promise): Error: (SystemJS) Unexpected token <
SyntaxError: Unexpected token <
    at Object.eval (http://localhost/UI/app/service/order/order.service.js:14:14)
    at eval (http://localhost/UI/app/service/order/order.service.js:57:4)
    at eval (http://localhost/UI/app/service/order/order.service.js:58:3)
Evaluating http://localhost/UI/node_modules/rxjs
Evaluating http://localhost/UI/app/service/order/order.service.js
Evaluating http://localhost/UI/app/component/order/order.module.js
Error loading http://localhost/UI/app/component/order/order.module.js
Run Code Online (Sandbox Code Playgroud)

然后基于这些异常跟踪,我抓住了我的bug.这里附上我的bug的根本原因供您参考.

在在线官方文档的一些示例中,它使用"rxjs"中的"import {Observable}"导入Observable;"

但它会导致我的项目中的先前异常.将它从'rxjs/Observable'更改为"import {Observable};",然后就可以了.


Ale*_*ski 0

您需要将http变量声明为 private 或 public 才能访问它,否则它只会在构造函数中可见。

constructor (private http: Http) {}
Run Code Online (Sandbox Code Playgroud)