0
votes

I tried to implement Angular 2 in Liferay 7. While the basic setup works, i'm unable to consume any json service. I wonder whether it is because of numerous 404s expecting node_modules to be under /web/guest. Please see example.

http://localhost:8080/web/guest/node_modules/zone.js/dist/zone.js 404

Also http://localhost:8080/o/rc-choice-web/js/system.config.js 404 (Not Found). This is actually under /meta-inf/resources/js.

I've copied node_modules under portlet root. I had issues compiling otherwise.

Also how do we consume liferay json service? How can we pass credentials with httpget?

Could any one please help me out?

1

1 Answers

0
votes

Liferay doesn't need Node Modules at all. Whatever you build in Angular 2, keep that output folder[dist] in tomcat.

Zone.js ->Responsible for Change detection in Angular 2. System.js-> Module Loader. Hence without this nothing will work.

Consuming Liferay Web service in Angular2 would require basic Auth in headers with [email protected] and it's password in headers.

Something like this.

let username: string = '[email protected]';
let password: string = 'test';
contentHeaders.append('Accept', 'application/json');
contentHeaders.append('Content-Type', 'application/json');
contentHeaders.append("Authorization", "Basic " + btoa(username + ":" + password));