From d763604930e175a2e4af68e4a7f560143362cf01 Mon Sep 17 00:00:00 2001 From: Manthan Ankolekar Date: Wed, 26 Apr 2023 18:16:07 +0530 Subject: [PATCH 1/2] feat: added title service & its ex --- README.md | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/README.md b/README.md index 93c9882..491e6ac 100644 --- a/README.md +++ b/README.md @@ -2001,6 +2001,152 @@ Angular's animation system is built on CSS functionality in order to animate any ## Meta tags +Title Service + +```jsx +import { BrowserModule, Title } from '@angular/platform-browser'; +``` + +```jsx +@NgModule({ + declarations: [ + AppComponent + ], + imports: [ + BrowserModule, + AppRoutingModule + ], + providers: [Title], + bootstrap: [AppComponent] +}) +export class AppModule { } +``` + +```jsx +export class TitleComponent implements OnInit { + constructor(private title:Title) { } +} +``` + +```jsx +ngOnInit() { + this.title.setTitle("Learn Angular") +} +``` + +```jsx +import { Component, OnInit } from '@angular/core'; +import { Title, MetaDefinition } from '@angular/platform-browser'; + +@Component({ + template: `

App Component

` +}) +export class AppComponent implements OnInit { + title = 'App Component'; + + constructor(private title:Title){ + } + + ngOnInit() { + this.title.setTitle("Learn Angular") + } + +} +``` + +Title Service + +```jsx +// app.module.ts +import { BrowserModule, Title } from '@angular/platform-browser'; +import { NgModule } from '@angular/core'; + +import { AppRoutingModule } from './app-routing.module'; +import { AppComponent } from './app.component'; +import { HomeComponent } from './home.component'; + +@NgModule({ + declarations: [ + AppComponent, HomeComponent + ], + imports: [ + BrowserModule, + AppRoutingModule + ], + providers: [Title], + bootstrap: [AppComponent] +}) +export class AppModule { } +``` + +```jsx +// app-routing.module.ts +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import { HomeComponent } from './home.component'; + +const routes: Routes = [ + {path: 'home', component:HomeComponent}, +]; + +@NgModule({ + imports: [RouterModule.forRoot(routes)], + exports: [RouterModule] +}) +export class AppRoutingModule { } +``` + +```jsx +// app.component.ts +import { Component } from '@angular/core'; +import { Title } from '@angular/platform-browser'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'] +}) +export class AppComponent { + title = 'Title Service Example'; + + constructor(private titleService:Title) { + } + + ngOnInit() { + this.titleService.setTitle(this.title); + } +} +``` + +```html + +

Title Service Example

+ + + + +``` + +```typescript +// home.component.ts +@Component({ + template: `

Home Component

` +}) +export class HomeComponent implements OnInit { + title = 'Home Component Title'; + + constructor(private titleService:Title){ + } + + ngOnInit() { + this.titleService.setTitle(this.title); + } + +} +``` + Meta Service ```jsx From d4eb626f888f939fadefce3a129e120545a32274 Mon Sep 17 00:00:00 2001 From: Manthan Ankolekar Date: Wed, 26 Apr 2023 18:19:04 +0530 Subject: [PATCH 2/2] feat: updated title service & its ex --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 491e6ac..9667cbb 100644 --- a/README.md +++ b/README.md @@ -2008,6 +2008,11 @@ import { BrowserModule, Title } from '@angular/platform-browser'; ``` ```jsx +import { BrowserModule, Title } from '@angular/platform-browser'; +import { NgModule } from '@angular/core'; +import { AppRoutingModule } from './app-routing.module'; +import { AppComponent } from './app.component'; + @NgModule({ declarations: [ AppComponent