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

查看:36
本文介绍了如何在 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 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天全站免登陆