Skip to content

Commit d1d7c31

Browse files
committed
added an example with Renderer2
1 parent c4faf28 commit d1d7c31

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

Angular4/inter-component/.angular-cli.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
33
"project": {
4-
"name": "w3"
4+
"name": "Inter-component communications"
55
},
66
"apps": [
77
{
@@ -178,6 +178,31 @@
178178
"dev": "environments/environment.ts",
179179
"prod": "environments/environment.prod.ts"
180180
}
181+
},
182+
{
183+
"name":"renderer",
184+
"root": "src",
185+
"outDir": "dist",
186+
"assets": [
187+
"assets",
188+
"favicon.ico"
189+
],
190+
"index": "index.html",
191+
"main": "main-renderer.ts",
192+
"polyfills": "polyfills.ts",
193+
"test": "test.ts",
194+
"tsconfig": "tsconfig.app.json",
195+
"testTsconfig": "tsconfig.spec.json",
196+
"prefix": "app",
197+
"styles": [
198+
"styles.css"
199+
],
200+
"scripts": [],
201+
"environmentSource": "environments/environment.ts",
202+
"environments": {
203+
"dev": "environments/environment.ts",
204+
"prod": "environments/environment.prod.ts"
205+
}
181206
}
182207
],
183208
"e2e": {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {Component, ElementRef, Renderer2, ViewChild} from "@angular/core";
2+
@Component({
3+
selector: 'app-root',
4+
template: `
5+
6+
<input type="text" placeholder="Enter your name">
7+
<input class="dummy" type="text" placeholder="dummy field" >
8+
9+
<button (click)="setFocusToDummy()">Set focus to the dummy input</button>
10+
11+
`
12+
})
13+
export class AppComponent {
14+
15+
// @ViewChild('dummy') dummy: ElementRef; // you'll need to add #dummy to the <input field>
16+
17+
constructor (private renderer: Renderer2){}
18+
19+
setFocusToDummy(){
20+
// this.renderer.selectRootElement(this.dummy.nativeElement).focus();
21+
22+
this.renderer.selectRootElement('.dummy').focus();
23+
}
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { BrowserModule } from '@angular/platform-browser';
2+
import { NgModule } from '@angular/core';
3+
4+
import { AppComponent } from './app.component';
5+
6+
@NgModule({
7+
declarations: [
8+
AppComponent
9+
],
10+
imports: [BrowserModule],
11+
bootstrap: [AppComponent]
12+
})
13+
export class AppModule { }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2+
import { AppModule } from './app/renderer/app.module';
3+
4+
platformBrowserDynamic().bootstrapModule(AppModule);

0 commit comments

Comments
 (0)