Code Monkey home page Code Monkey logo

angular-multiple-controllers-lab-g-416's Introduction

Multiple Controllers

Objectives

  • Write a new Controller
  • Nest the second Controller inside the other in the View
  • Access inherited properties from the parent Controller
  • Update a parent Controller from the child Controller

Instructions

Copy the directory structure from this repo.

Create the controller ContactController inside js/app/controllers/ContactController.js. Create the values name, email and phone inside the controller. Create a function to update the name to a different value - e.g.

function ContactController() {
  var vm = this;

  this.changeName = function () {
    vm.name = 'Something else!'
  }
}

We create the variable vm to keep a reference to the this object. That way, inside functions, we don't have to care what the this keyword is - we can update our vm variable instead. We use the variable vm because even though this is called a controller, it is really more like our View Model.

Initialize this controller in our HTML using ng-controller. Make sure you use the controllerAs syntax, assigning the controller to the variable contact. Inside this element, display the contact's name, email and phone number.

Create another controller named StaffController inside js/app/controllers/StaffController.js. Create the values name, email and phone inside the controller.

Initialize StaffController inside the HTML element for our ContactController. Inside this, display the staff's name, email and phone number. Then, create a button with the attribute ng-click="contact.changeName()". This should, when clicked, update our ContactController's name value.

Resources

angular-multiple-controllers-lab-g-416's People

Contributors

aturkewi avatar ipc103 avatar mdjurdj1 avatar toddmotto avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.