简体   繁体   English

如何从控制台执行Angular 2+功能?

[英]How to execute Angular 2+ functions from console?

My app will run encapsulated inside a cromium browser with chromiumfx. 我的应用程序将运行在带有chromiumfx的铬浏览器中。

chromiumfx are capable to execute any existing JS functions just like you operating a console. chromefx能够执行任何现有的JS功能,就像您操作控制台一样。

I've this application... 我有这个应用程序...

 import { Component } from '@angular/core';
 import { GlobalService} from './global.service';
 import {Router} from "@angular/router";
 @Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
 })
 export class AppComponent {

  constructor(private gs: GlobalService, private router: Router) {

   }
  tst() {
    console.log('hello');
   }
 }

I need to execute tst() from the console to simulat an action from cromiumfx. 我需要从控制台执行tst()来模拟cromiumfx的操作。 Any help ? 有什么帮助吗?

In dev mode you can just write: 在开发模式下,您可以编写:

ng.probe($0).componentInstance.tst()

where $0 points to your component host element. $0指向组件宿主元素。

Ng-run Example Ng运行示例

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM