Skip to main content

Posts

Showing posts from May, 2019

Services in Drupal 8

In Drupal 8  service is any object managed by the services container. Drupal 8 introduces the concept of services to decouple reusable functionality and makes these services pluggable and replaceable by registering them with a service container. As a developer, it is best practice to access any of the services provided by Drupal via the service container to ensure the decoupled nature of these systems is respected. services are used to perform operations like accessing the database or sending an e-mail. like below: $connection = \ Drupal :: database ( ) ; $result = $connection - > select ( 'node' , 'n' ) - > fields ( 'n' , array ( 'nid' ) ) - > execute ( ) you can create your own services, like create common used function with in the class and use it any where, It works like global functions. To create our own services, just create a services file like modulename.services.yml , services: drupalup_service.co...

Typescript Introduction

Data type Keyword Description Number number Double precision 64-bit floating point values. It can be used to represent both, integers and fractions. String string Represents a sequence of Unicode characters Boolean boolean Represents logical values, true and false Void void Used on function return types to represent non-returning functions Null null Represents an intentional absence of an object value. Undefined undefined Denotes value given to all uninitialized variables TypeScript provides data types as a part of its optional Type System. The data type classification is as given below − let a: number //e.g 1, 2, 3 let b: boolean //e.g true, false let c: string //e.g "abel agoi" let d: any //this can take any other types let e: number[] //array of numbers e.g [1, 3, 54] let f: any[] //any array e.g [1, "abel agoi", true] Arrow function : In javascript, we ca...

Drupal 8 QA

API'S or Images has been blocked by CORS policy in Drupal 8: When use REST Api in angular , then through the error CORS policy, to avoid ir Change config in sites/default/services.yml cors.config:     enabled: true     # Specify allowed headers, like 'x-allowed-header'.     allowedHeaders: ['x-csrf-token','authorization','content-type','accept','origin','x-requested-with']     # Specify allowed request methods, specify ['*'] to allow all possible ones.     allowedMethods: ['*']     # Configure requests allowed from specific origins.     allowedOrigins: ['*']     # Sets the Access-Control-Expose-Headers header.     exposedHeaders: false     # Sets the Access-Control-Max-Age header.     maxAge: false     # Sets the Access-Control-Allow-Credentials header.     supportsCredentials: false Function to load only class name ...

Angular Fundamentals:

Interpolation : Pass data from component file to template called interpolation,We can pass variable & function to the template files like below, import { Component, OnInit } from '@angular/core'; @Component({   selector: 'app-topmenu',   template: ` {{name}} {{getsirname()}} `,   styles: [] }) export class TopmenuComponent implements OnInit {   public name = "Dharmendra Singh";   constructor() { }   ngOnInit() {   }   getsirname(){ return "rajput"; }} Pipes : Pipes are used to change the data before display on the view, like uppercase.lowecase,slice etc. selector: 'app-topmenu',   template: ` {{name | uppercase}}  {{name | lowercase}}  {{ post | json }}  //  ... `,   styles: [] ng foor loop in angular with add class dynamic on last element  < span *ngFor = "let two of last_two; let last = last;" > < div class = "single-to...