Skip to content

jDrupal and Angular 4 (TypeScript) #86

@liquidcms

Description

@liquidcms

I saw an old post of someone looking for jDrupal support for Angular 2. I'm a bit late but i got this working with Angular 4 (TypeScript).

npm install jdrupal

in angular.json under "scripts" i added: "node_modules/jdrupal/jdrupal.js"

using an import statement should have worked but i couldn't figure it out.

then in mypage.page.ts


import { Component, OnInit } from '@angular/core';
// import * as Drupal from 'jdrupal';

declare var Drupal: any;

@Component({
  selector: 'app-drupal-test',
  templateUrl: './drupal-test.page.html',
  styleUrls: ['./drupal-test.page.scss'],
})
export class DrupalTestPage implements OnInit {

  constructor() {}

  ngOnInit() {
    Drupal.settings.site_path = 'http://qleva.liquidcms.org';
    Drupal.settings.endpoint = 'rest';
    this.initDrupal();
    this.userLogin();
  }

  initDrupal() {
    system_connect({
      success: function(result) {

        // Prepare a message for the user.
        const text = result.user.uid === 0 ? 'Hello World' : 'Hello ' + result.user.name;

        // Show the message in the paragraph.
        document.getElementById('msg').innerHTML = text;

      }
    });
  }

  userLogin() {
    user_login('qleva-admin', 'qpoiqpoi', {
      success:function(result) {
        document.getElementById('useremail').innerHTML = result.user.mail;
      },
      error:function(xhr, status, message) {
        alert(message);
      }
    });
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions