Angular - Components - Code Organization - One-way and Two-way Binding #20
akash-coded
started this conversation in
Tasks
Replies: 3 comments
-
|
one-way-binding.component.html <div>
<p>My name is {{firstName}} {{lastName}}</p>
<button (click) = "clickEventFunc()">click for alert message</button>
</div>one-way-binding.component.ts import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-one-way-binding',
templateUrl: './one-way-binding.component.html',
styleUrls: ['./one-way-binding.component.css']
})
export class OneWayBindingComponent implements OnInit {
constructor() { }
firstName: String = "rakesh";
lastName : String = "rajbanshi"
clickEventFunc():void{
alert("hello MOTO");
}
ngOnInit(): void {
}
}
two-way-binding.component.html <div>
<label>Enter the value:</label>
<input type="text" [(ngModel)] = "val"/>
<br>
<h2>You entered : {{val | uppercase}}</h2>
</div>two-way-binding.component.ts import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-two-way-binding',
templateUrl: './two-way-binding.component.html',
styleUrls: ['./two-way-binding.component.css']
})
export class TwoWayBindingComponent implements OnInit {
constructor() { }
val : string = ""
ngOnInit(): void {
}
}app.component.html <app-one-way-binding></app-one-way-binding>
<app-two-way-binding></app-two-way-binding> |
Beta Was this translation helpful? Give feedback.
0 replies
-
//APP.COMPONENT.HTML
<button (click)="handlechange()">search</button>
<input type="text" [(ngModel)]="text"/>
<p>{{text}}</p>
//APP.COMPONENT.TS
export class AppComponent {
text:string=""
handlechange()
{
console.log("Hiiiii");
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
one-way-binding-interpolation.html one-way-binding-interpolation.ts one-way-binding-event.html one-way-binding-event.ts two-way-binding.html two-way-binding.ts |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Uh oh!
There was an error while loading. Please reload this page.
-
Organize the codebase of this app by putting appropriate code into the suitable nested or sibling components.
Beta Was this translation helpful? Give feedback.
All reactions