如何在Angular 6中使用node.js模块? [英] How to use node.js module with Angular 6?

查看:78
本文介绍了如何在Angular 6中使用node.js模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular 6和TypeScript的新手.有人可以向我展示在Angular 6中使用node.js第三方模块的正确方法吗?

I am newbie in Angular 6 and TypeScript. Can someone show me the right way to use node.js third-party module in Angular 6?

例如,我想创建具有消耗和向SOAP wsdl方法发出请求的功能的组件.

For example i want to create component with ability to consume and make requests to SOAP wsdl methods.

通过使用 npm install 添加到package.json来安装它.

Did installed it by adding to package.json with npm install.

尝试像这样使用node-soap npm模块:

Trying to use node-soap npm module like this:

import { Injectable } from '@angular/core';
import * as soap from 'node-soap';

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

  getOrderInfo() {
    const url = 'http://my-example-api.com/WCF/ClientService.svc?singleWsdl';
    let args = {
      login: 'login',
      password: 'password',
      orderNumber: 'F976638'
    };
    soap.createClient(url, function(err, client) {
      client.GetOrderInfo(args, function(err, result) {
        console.log(result);
      });
    });
  };
}

然后将该服务注入组件并进行渲染,只是为了测试该服务...

Then inject this service into component and render it, just to test the service...

但是在 ng服务期间出现了一些错误:

But got some error during ng serve:

ERROR in ./node_modules/node-soap/client.js
Module not found: Error: Can't resolve 'http' in '/home/cadistortion/WebstormProjects/my-ng-app/node_modules/node-soap'

谢谢!

推荐答案

很简单,在您的URL中有您的API节点.您需要更多express.js(或其他)才能上班.BD-例如MongoDB或其他或Json.

it's easy, in your url have your API node. You go need more, express.js(or other) for get work. BD - like MongoDB or other or Json.

查看此视频和其他同一用户 https://www.youtube.com/watch?v = M-G48Gf2Xl0 完成了如何使用MEAN Stack创建博客

See this vídeo and other the same user https://www.youtube.com/watch?v=M-G48Gf2Xl0 is complete how create blog using MEAN Stack

这篇关于如何在Angular 6中使用node.js模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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