在生产模式下从控制台调用 Angular2 组件方法 [英] Calling Angular2 Component methods from Console in Production mode

查看:27
本文介绍了在生产模式下从控制台调用 Angular2 组件方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在生产模式下调用组件或服务方法?

Is there a way to call component or service methods in Production mode?

我知道可以使用 ng.probe 和 Angular2 调试应用 Augury 调试应用程序:https://augury.angular.io/

I know an application can be debugged using ng.probe and with the Angular2 debugging app Augury: https://augury.angular.io/

但是,这些仅在开发模式下才有效.

However, these only works when in development mode.

推荐答案

据我所知,没有内置方法.

There's no built-in method, to my knowledge.

这可以通过 URL 哈希中的自定义标志来处理

This can be handled by custom flag in URL hash

import {enableProdMode} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';

const DEV_MODE = 'DEV_MODE';
const DEV_MODE_REGEXP = new RegExp('(?:^|;)' + DEV_MODE + '$');

const IS_DEV_MODE = DEV_MODE_REGEXP.test(window.location.hash);

if (window.ENV !== 'prod' || IS_DEV_MODE) {
  if (IS_DEV_MODE) {
    window.location.hash = window.location.hash.replace(DEV_MODE_REGEXP, '');
  }
} else {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(...);

或者通过在 window.name 中放置一个标志,就像在 reloadWithDebugInfo 在 AngularJS 中.

Or by putting a flag into window.name, like it was done in reloadWithDebugInfo in AngularJS.

这篇关于在生产模式下从控制台调用 Angular2 组件方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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