如何从浏览器控制台调用服务进行调试?

时间:2021-05-30 11:22:12

标签: javascript angular typescript angular11

我想从浏览器控制台调用我的 ApiService

我尝试了Call a service function from browser console in angular 6中解释的内容:

@Injectable({
  providedIn: 'root'
})
export class ApiService {

  constructor(private http: HttpClient) {window['myService'] = this}

导致编译错误的原因:

Error: ../services/api.service.ts:12:49 - error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.

12   constructor(private http: HttpClient) {window['ApiService'] = this; }

我也尝试从控制台运行它:

angular.element(document).injector().get('ApiService');

但是由于出现以下错误,似乎没有加载角度依赖项:

Uncaught ReferenceError: angular is not defined
    <anonymous> debugger eval code:1

有什么线索可以在这个主题上取得进展吗?

0 个答案:

没有答案
相关问题