A conditional statement can compare two values. Here we check if one variable we declared is greater than another. It is true so the code executes.

Similar documents
ADVANCED JAVASCRIPT #8

ADVANCED JAVASCRIPT. #7

"a computer programming language commonly used to create interactive effects within web browsers." If actors and lines are the content/html......

The Structure of the Web. Jim and Matthew

a Very Short Introduction to AngularJS

Getting Started with

Manual Html A Href Onclick Submit Form

The DOM and jquery functions and selectors. Lesson 3

Design Document V2 ThingLink Startup

P a g e 1. Danish Technological Institute. Scripting and Web Languages Online Course k Scripting and Web Languages

AngularJS. Beginner's guide - part 1

AngularJS AN INTRODUCTION. Introduction to the AngularJS framework

EXPRESSIONS IN ANGULARJS

Chapter 9 Introducing JQuery

JQuery WHY DIDN T WE LEARN THIS EARLIER??!

Nagaraju Bende

Getting Started with HTML5 using BlackBerry WebWorks

THE PRAGMATIC INTRO TO REACT. Clayton Anderson thebhwgroup.com WEB AND MOBILE APP DEVELOPMENT AUSTIN, TX

Client Side JavaScript and AJAX

Manual Html A Href Onclick Submit Button

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

Understanding Angular Directives By Jeffry Houser

What is AngularJS. à Javascript Framework à MVC à for Rich Web Application Development à by Google

CS7026. Introduction to jquery

Multimedia im Netz Online Multimedia Winter semester 2015/16

Introduction to Web Development

Creating Effective Websites using AngularJS

IN4MATX 133: User Interface Software

Website Development Lecture 18: Working with JQuery ================================================================================== JQuery

AngularJS Introduction

Introduction to WEB PROGRAMMING

ThingLink User Guide. Andy Chen Eric Ouyang Giovanni Tenorio Ashton Yon

CodeValue. C ollege. Prerequisites: Basic knowledge of web development and especially JavaScript.

CSS is applied to an existing HTML web document--both working in tandem to display web pages.

Software Architecture Documentation for the JRC MYGEOSS app for Invasive Species project

Diploma in Mobile App Development Part I

Using AJAX to Easily Integrate Rich Media Elements

Basics of Web Technologies


Comprehensive AngularJS Programming (5 Days)

WELCOME TO JQUERY PROGRAMMING LANGUAGE ONLINE TUTORIAL

Unveiling the Basics of CSS and how it relates to the DataFlex Web Framework

Single Page Applications using AngularJS

Sample CS 142 Midterm Examination

Design and Implementation of Single Page Application Based on AngularJS

Modern and Responsive Mobile-enabled Web Applications

Session 17. jquery. jquery Reading & References

Jquery Ajax Json Php Mysql Data Entry Example

HTML Forms. 10 September, Dr Derek Peacock. This is a short introduction into creating simple HTML forms. Most of the content is

Full Stack Web Developer

ADDING CSS TO YOUR HTML DOCUMENT. A FEW CSS VALUES (colour, size and the box model)

Client-side Techniques. Client-side Techniques HTML/XHTML. Static web pages, Interactive web page: without depending on interaction with a server

welcome to BOILERCAMP HOW TO WEB DEV

Source. Developer Guide / forms

Financial. AngularJS. AngularJS. Download Full Version :

Why Use A JavaScript Library?

ToDoList. 1.2 * allow custom user list to be passed in * publish changes to a channel ***/

Web Application Development

AR0051: Digital Presentation Portfolio. AR0051 JQuery. Nord-Jan Vermeer Henry Kiksen. Challenge the future

SEEM4570 System Design and Implementation Lecture 04 jquery

Angular 2: What s new? Jonas Bandi, IvoryCode GmbH

Css Manually Highlight Current Link Nav Link

1.2 * allow custom user list to be passed in * publish changes to a channel

Web Development & Design Foundations with HTML5

jquery Tutorial for Beginners: Nothing But the Goods

Introduction to using HTML to design webpages

Connecting Angular and CFML

HTML5 and CSS3 The jquery Library Page 1

User Interaction: jquery

CSC Web Technologies, Spring HTML Review

Financial. AngularJS. AngularJS.

Jquery Manually Set Checkbox Checked Or Not

Tarek Elachkar, VP Customer Solutions - Jahia A real world story of Angular and Apache Unomi integration.

Static Webpage Development

WEB DESIGNING COURSE SYLLABUS

JQuery and Javascript

High Performance Websites Questions [10 pts] Computer Science nd Exam Prof. Papa Thursday, May 4, 2017, 6:00pm 7:20pm. Student ID Number:

Web Technologies II + Project Management for Web Applications

CSS Design and Layout Basic Exercise instructions. Today's exercises. Part 1: Arrange Page into Sections. Part 1, details (screenshot below)

CSC 337. jquery Rick Mercer

About Me. Name: Jonathan Brown. Job: Full Stack Web Developer. Experience: Almost 3 years of experience in WordPress development

CREATING A WEBSITE USING CSS. Mrs. Procopio CTEC6 MYP1

Front End. Presentation Layer. UI (User Interface) User <==> Data access layer

Last class we looked at HTML5.

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Frontend Frameworks. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Front End Programming

HTML5. HTML5 Introduction. Form Input Types. Semantic Elements. Form Attributes. Form Elements. Month Number Range Search Tel Url Time Week

1. Setup a root folder for the website 2. Create a wireframe 3. Add content 4. Create hyperlinks between pages and to external websites

AngularJS Fundamentals

THE ROAD TO ANGULAR 2.0

AngularJS. CRUD Application example with AngularJS and Rails 4. Slides By: Jonathan McCarthy

mongodb-tornado-angular Documentation

3 Days Training Program

input[datetime-local] DIRECTIVE IN ANGULARJS

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

Dreamweaver Domain 5: Organizing Content by Using Dreamweaver CS5

Events & Callbacks (ESaaS 6.5)! 2013 Armando Fox & David Patterson, all rights reserved

Part 1: Data-Binding Frameworks (e.g. AngularJS)

Transcription:

ANGULARJS #7

7.1 Review JS

3 A conditional statement can compare two values. Here we check if one variable we declared is greater than another. It is true so the code executes. var cups = 15; var saucers = 4; // check if cups is greater than (>) saucers if (cups > saucers) { alert("we need to order more saucers"); }

4 You can save code as a function and execute it repeatedly // specify a variable in the brackets. You can use it inside your function. function welcome(message) { alert("welcome to the website " + message); } // execute your function and place a value/variable in the round brackets. welcome("mary"); var name = "Peter"; welcome(name);

7.2 jquery

6 jquery is a JavaScript library. You can load it from Google's CDN service or download and include in your site folder. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min. js"></script> Before executing jquery code, you should tell the browser to wait until the page has finished loading. $(document).ready( function () { }); //code here

7 The basic syntax of jquery is $(selector).action(); Like CSS the selector is the HTML element you want to target. You can then perform an action to that element/those elements. The $ symbol is used at the start of all jquery lines of code. It is telling the browser to parse the following code using jquery. The selector is based on the CSS model. You can use general HTML names, classes and ids: $("h1") selects all h1s. $(".bigger") selects all HTML elements with class="bigger". $("#intro") selects the HTML element with id="intro".

8 The syntax for events is similar to actions: $(selector).click(); $('p').click(); Inside the round brackets after your event, you can write a function that will get executed as that event happens. $(".trigger").click( function () { $(".nav").slidetoggle(); });

9 hover() has one big difference to click, you should define 2 functions. One for hovering on, one for when the hover ends. $("p").hover( function () { alert("i hovered on a paragraph"); }, function () { alert("i hovered off a paragraph"); });

10 submit() is the same syntax as click(). You can declare one function to be called when a user submits a form. <form> <input type="text"> <input type="submit" value="order Now"> </form> $("form").submit( function () { confirm("do you definitely agree to the Terms and Conditions?"); });

11 blur() is the same syntax as click(). You declare a function for when a user moves focus away from a form field. <input type="password"> <p id="error"></p> $("input:password").blur( function () {//input:password is input with type="password" var password = $(this).val();//$(this).val() is the contents of the current item, the field. if(password.length < 8){//password.length is the number of characters in the string $("#error").html("you must use at least 8 characters"); } else { $("#error").html(""); } });

7.3 jquery Validation

13 A very useful plugin is for validating forms. It can be downloaded at http://jqueryvalidation.org Download and unzip the plugin folder. The only file required to use the plugin is dist/ jquery.validate.min.js, move this to your js/ folder. Include it in your HTML file using: <script src="js/jquery.validate.min.js"></script>

14 The validation plugin is setup and ready to be used. The validation plugin is built around HTML 5 form attributes and uses existing input types e.g. type="email". <form id="signup"> <p><label for="username">username</label> <input type="text" id="username" minlength="6" required></p> <p><label for="email">email Address</label> <input type="email" id="email" required></p> <p><label for="password">password</label> <input type="password" id="password" required minlength="8"></p> <input type="submit" value="signup" > </form> Then in your JS code: $(document).ready( function () { $("form").validate(); });

7.4 AngularJS

16 AngularJS is a JavaScript front-end framework. Many online applications like Netflix/GMail run on Javascript Frameworks. A framework is different to a library. Where a library has functions you can use how you like, a framework is setup to work a certain way. A framework like Angular can parse API endpoints and create HTML content.

17 Using AngularJS This is the quickest, simplest implementation of AngularJS. 1. Load their JS file in the <head> of your HTML page <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min. js"></script> 2. Add ng-app to your opening <html> tag <html ng-app>

18 2 way Data Binding AngularJS can track if values change and update accordingly. <input type="text" ng-model="firstname" placeholder="enter your first name"> <h1>hi there {{firstname}}!</h1> With the ng-model attribute, you are linking the value of the input field to a model/variable Curly brackets {{ }} are a templating feature. They allow you to output content.

19 if statements AngularJS can display content conditionally. <input type="text" ng-model="firstname" placeholder="enter your first name"> <h1 ng-if="firstname">hi there {{firstname}}!</h1> Here we are checking if firstname is true, if so the <h1> displays

20 MVC Angular is built on the Model View Controller principle. The Model represents your data. The Controller can manipulate the data had handle interactions from View to the Model. The View is where your data is displayed. Your model, controller and view should be distinct. In this way your code should be more reusable. As an AngularJS App gets more complicated we use Controllers.

21 Using a Controller To use a Controller we must give our app a name <html ng-app="todoapp"> We're going to create an external js file as well and link to our HTML <script src="todo.js"></script> And last we set an attribute ng-controller on a div where the controller will show data <div ng-controller="todolistcontroller as todolist"> </div>

22 todo.js In our JS file we define a controller and add it to our app. We assign the controller to a variable to make it easier to use again. Last we create an array of todo objects. angular.module('todoapp', []).controller('todolistcontroller', function() { var todolist = this; todolist.todos = [ {text:'html Assignment', complete:true}, {text:'css Assignment', complete:true}, {text:'js Assignment', complete:false}, {text:'end Assignment', complete:false}]; });

23 ng-repeat Back in our HTML file we can loop through our array of todos using the attribute ng-repeat <ul> <li ng-repeat="todo in todolist.todos"> {{todo.text}} </li> </ul> We can also display a count You have {{todolist.todos.length}} todos

24 ng-model We can use the todo.complete value to display if a todo is completed. <input type="checkbox" ng-model="todo.complete"> We can improve how the todo is displayed <span class="complete-{{todo.complete}}"> {{todo.text}} </span> <style>.complete-true{ text-decoration:line-through; } </style>

25 Angular function You can define a function inside your controller and call it in your view. todolist.remaining = function() { var count = 0; angular.foreach(todolist.todos, function(todo) { if(todo.complete) count +=1; }); return count; }; To call in your HTML we write the controller.function name with round brackets. You have {{todolist.remaining()}} of {{todolist.todos.length}} todos outstanding

26 Call a angular function with an event You can use ng-click to run code on a click event. <a href="#" ng-click="todolist.archive()">archive</a> We can write a function to loop through our todos and only keep ones outstanding. todolist.archive = function() { var oldtodos = todolist.todos; todolist.todos = []; angular.foreach(oldtodos, function(todo) { if (!todo.complete) todolist.todos.push(todo); }); };

27 Call a angular function with a submit event You can also use ng-submit to run code on a click event. <form ng-submit="todolist.addtodo()"> <input type="text" ng-model="todolist.todotext"> <input type="submit" value="add todo"> </form> Then in your controller we write a function that pushes(adds) a new object into the todolist array. todolist.addtodo = function() { todolist.todos.push({text:todolist.todotext,done:false}); todolist.todotext = ''; };