Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

How to use node.js module with Angular 6?

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?

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

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

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...

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'

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...