MEAN Stack
  • MEAN Stack
  • Getting Started
    • Course Requirements
  • Setup Local Development Environment
    • Git and Gitbash Installation
    • VSCode Installation
    • Node Installation
    • VS Code Live Share
  • Web and Javascript Fundamentals
    • Day One - Intro
    • WK1: Web Fundamentals
      • Let's Git it!
      • HTML, CSS, JS
      • Reading Code & Fixing Errors
        • Challenge 1 - Reading Code & Fixing Errors
        • Challenge: Reading Code and Fixing Errors
      • Homework WK1
    • WK2: JS Versions
      • ES6 and beyond
      • TypeScript
      • Palindrome Challenge
      • Problem Solving
      • Homework WK2
  • Angular
    • WK3: Angular
      • Intro to Angular
        • Angular CLI Install
        • Angular Architecture
          • App Module
          • Modules Explained
          • App Component
          • Angular Files
          • Recap
      • Components & Data Binding
        • Component Boiler Plate
        • Creating a Component
        • Using A Component
        • Component's and CSS Styling
        • Data Binding Challenge
        • User Input with - [(ngModel)]
        • Login Page Challenge
      • Routing
        • Creating A Routing Module
        • Adding Routes
        • Router Outlet Setup
        • Using the Router
        • Routing Challenges
      • Homework WK3
    • WK4: Angular Midterm Project
      • Structural Directives
      • Error Debugging in Angular
        • Tour of Errors Challenge
        • Angular Errors Challenge
      • Intro to Services
      • Midterm Project: Bank Application
    • WK5: Data Flow
      • Intro to API
      • HTTP Requests to API
      • Higher-Order Functions
      • YouTube API
      • Homework WK5
    • Angular Cheat Sheet
  • Backend - Loopback & Mongo
    • WK6: Intro to Backend
      • Announce Final Project
      • Intro to RESTful API
      • Install Loopback
      • Create a MongoDB
      • Connect Loopback to MongoDB
      • Introduce API Explorer
      • Create User Models
    • WK7: Backend Auth & Database Setup
      • Register
      • Login
      • Setup Token Authentication
      • Create Persisted Models
      • Access Control Settings
    • WK8: Final Project Relations
      • Relations
  • Deployment
    • Big Picture
    • Deploying Loopback
      • Learn Environment Variables
      • Using Environment Variables in Loopback
      • Production Environment
      • Deploy to Heroku
        • Create a Heroku App
    • Deploy an Angular App
      • Deploying an Angular App to Netlify
Powered by GitBook
On this page
  • Challenges
  • Angular Structural Directives
  • Angular 2 way data-binding
  1. Angular
  2. WK3: Angular

Homework WK3

PreviousRouting ChallengesNextWK4: Angular Midterm Project

Last updated 5 years ago

Challenges

Angular Structural Directives

Angular 2 way data-binding

In angular in order to accept user input we need to use two-way data binding, between the HTML and Component. We use [(ngModel)] to bind a value from the <input>. This is useful for login page, register pages, search bars and other forms that require user specific input.

Our component

my-component.ts
Import { Component } from "@angular/core"; (

@Component({
  selector: "my-component",
  templateURL: './my.component.html'.
  styles: [['h1 { font-weight: normal; }']]   
})

export class MyComponent {
  name = ""
}

Line 10: the name property the above component is going to store the value from the user <input>, however right now it is just an empty string.

Out template for the component

my.component.html
<input [(ngModel]="name" >

Notice the name in quotes, that is referring to the name on the component in my.component.html. This is how you receive information from the user with angular's two way data binding.

Challenge - Data Binding
Challenge - Login Page
Challenge - Angular Routing