This is coming from the w3schools.com resource. Click on the link or or the image to access additional resources.
Table of Contents:
You set this up using the https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js in your header.
Be aware that the process of introducing an Angular dynamic into a page is a process referred to as "auto-bootstrapping." You'll see that spelled out below, but it's good to be aware of this terminology.
A) Auto Bootstrapping (back to top...)
Here's a great article from https://www.quora.com/What-are-the-differences-between-bootstrap-and-angular-js that spells out the difference between "auto-bootrapping" and Bootstrap.
Any word that is greyed out and underlined represents a "tooltip." You can hover over it and see some additional information about that particular term. Any edits to that functionality can be investigagted by heading out to tooltipster.com.
A) The ng-app, ng-model and ng-bind Directives
A) Curly Braces
A) Break it Down
Up to now we've mentioned AngularJS Directives in their most basic context as far as what's needed to get some rudimentary AngularJS functionality off the ground. Now, let's dig a little deeper.
A) ng-app, ng-init, ng-model
B) Data Binding
C) Create Your Own Directives
1) Restrict Your Directives
The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.
A) Basic Example
B) Two Way Binding
C) Validate User Input
D) Application Status
E) CSS Classes
The ng-model directive binds data from the model to the view on HTML controls (input, select, textarea).
A) Data Model
B) HTML View
C) Two-Way Binding
A slight pause in order to reinforce the basics that have been covered thus far.
A) Directives
1) app
2) init
3) model
B) Basic Concepts
1) Binding and Expressions
2) Models, Modules and Controllers
A) Objects
B) External Files and Methods
Adding a little more depth to the way in which we've looked at scopes thus far.
A) MVC Illustration
B) Scope Usage
1) Arguments and Parameters
C) Root Scope
Filters can be added to expression by using the pipe character (|), followed by a filter.
A) JS Filters
1) uppercase
2) order by
3) filter by
4) user input (very cool)
5) table sorter
6) custom sorter
A) DOM Review
1) DOM
2) node
3) Object
B) Location
C) http Service
D) Timeout Service
E) Interval Service
F) Custom Service
G) Custom Service w/ Filter
This is an Angular service that reads data from remote servers. We went over this earlier in the context of "Services."
A) Simple "GET"
B) Methods
C) Properties
1) Error Messages
2) JSON
You're grabbing the content from "customers.php" using the "http.get" service, but now you're displaying it in a table with some cool little enhancments.
A) Basic Table
1) CSS Styling
2) orderByFilter
3) uppercaseFilter
4) Add Index
5) Using $odd or $even
We're using the Angular "ng-options" to pull this off..
A) Basic Example
B) Options vs Repeat
1) ng-repeat w/ a String
2) ng-repeat w/ Object
C) Data Source as an Object
1) The Value in a "Key-Value" Pair
2) The Property Value of the Value Object
Retrieving data from a database is absolutely no problem, you've just got to make sure that it's being returned in a JSON format.
A) MySQL
B) Other Databases
You can use directives to bind application data to the attributes of HTML DOM elements.
A) ng-disabled
B) ng-show / ng-hide
AngularJS has its own HTML events directives.
A) List of Event Listeners
1) Mouseover
2) ng-click
i) ng-click -> function
3) $event object
Forms in AngularJS provide data-binding and validation of input controls.
Cool stuff!
A) Data Binding
1) Input Text
2) Checkbox
3) Radio Button / SELECT
4) Form Application
With Angular you've got a pretty verbose way of validating form input.
A) Field Required / Email Validation
B) Form and Input State
Angular API is a set of global JavaScript functions for performing some basic tasks...
A) Examples (lowercase, uppercase, isString, isNumber)
W3.CSS is a modern CSS framework that features built in resposiveness. And, it plays very nicely with Angular...!
A) Example of Form Using Angular and W3.CSS
With Angular JS, you can include HTML content using the ng-include directive...
A) Basic Example
B) Include Cross Domains
C) Include Cross Domains
Make things move, baby...!
A) Basic Example
B) Angular Classes
C) CSS Transitions & Animations
1) CSS Transitions
2) CSS Animations
Routing allows you to navigate to other pages in your site without having to reload the site.
A) Basic Example
1) Route Module
2) The ngRoute Dependency
3) ng-view Directive
4) $routeProvider
B) Controllers
C) Templates
Now we're going to put all of this together and build a real world application using AngularJS.
Here we go!
A) My Shopping List
1) Create List of Products
2) Add Inputs
3) Remove Items
4) Error Handling
5) Add Some Style
Bootstrap:
What it is?
It is a set of well structured CSS styles, Grid classes and JavaScript components. The people at Twitter developed it and now it's a part of open source community and almost any personal project or startup project uses it.
These common tools including styles, css classes, javascript components helps us to develop at a faster pace especially for those who doesn't have experience in frontend development.
What it's not?
It's not a frontend framework which provides structure to your application or common functionality like routing, controllers and models, MVC architecture etc.
AngularJS:
What it is?
It is developed and maintained by Google and is one of the top 3 JavaScript Frameworks out there. It provides set of components to structure your app and organize the project. Made for ambitious JavaScript Single Page Applications, AngularJS provides tools to make life of Frontend Developers easier by providing set of guidelines and architecture to application.
What it's not ?
It doesn't provide CSS styles, Grid classes or JavaScript components like Modal, Tabs, Navigation Bar, Dropdown menu etc.
As far as "Auto Bootstrapping," here you go:
Angular initializes / bootstraps automatically upon DOMContentLoaded event or when the angular.js script is downloaded to the browser and the document.readyState is set to complete. At this point AngularJS looks for the ng-app directive. When the ng-app directive is found then Angular will:
A) The ng-app, ng-model and ng-bind Directives (back to top...)
From W3 Schools.com: "AngularJS directives are extended HTML attributes with the prefix ng- . The ng-app directive initializes an AngularJS application. The ng-init directive initializes application data. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data."
You've got a couple of "ng directives" to consider.
- Load the module associated with the directive.
- Create the application injector.
- Compile the DOM starting from the ng-app root element.
- This process is called auto-bootstrapping.
- You should not use the ng-app directive when manually bootstrapping your app.
- You should not mix up the automatic and manual way of bootstrapping your app.
- Define modules, controller, services etc. before manually bootstrapping your app as defined in above examples.
- The ng-app defines an AngularJS application. While this isn't the best illustration, think of "ng-app as a doctype, similiar to <!DOCTYPE html> in that you'll only do this once per page. You can have more than one Angular component on a page, but we'll look at that later. For the examples you see below, know that you have to declare the "ng-app" and you do that only once. All the examples you see are in iframes.
- The ng-model directive binds the valut of HTML controls to app data
- The ng-bind directive binds application data to the HTML view
Input something in the input box:
Name:
- <div ng-app="myApp" ng-controller="myCtrl">
- First Name: <input type="text" ng-model="firstName"><br>
- Last Name: <input type="text" ng-model="lastName"><br>
- <br>
- Full Name: {{firstName + " " + lastName}}
- </div>
- <script>
- var app = angular.module('myApp', []);
- app.controller('myCtrl', function($scope) {
- $scope.firstName= "John";
- $scope.lastName= "Doe";
- });
- </script>
- the "ng-app" directive initializes the AngularJS application by defining the root element and will automatically auto-bootstrap the application when the web page is loaded
- The "ng-init" directive initializes application data - it defines initial values, although normally you won't use "ng-init," as much as you'll use a controller or module instead
- The "ng-model" directive
- binds the value of HTML controls (input, select, textarea) to application data
- it can also provide type validation for application data (number, email, required)
- provide status for application data (invalid, dirty, touched, error)
- provide CSS classes for HTML elements
- bind HTML elements for HTML forms
- E for Element name
- A for Attribute
- C for Class
- M for Comment
- Your "module" is your collection of AngularJS Objects etc.
- Your "model" is your "Conjunction Junction" in the way it couples AngularJS data with specific HTML elements. If you're thinking in terms of the traditional MVC architecture, think of it as your "View"
- Your "controller" is just like what you have with the MVC architecture in that the Controller facilitates the communication between your "view" and your "information" which is provided by your "scope..."
//"scope" is an object consisting of properties and values and in that way it serves as your "model" when you're thinking in terms of MVC
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName="John";
$scope.lastName="Doe";
$scope.fullName= function() {
return $scope.firstName + " " + $scope.lastName;
};
});
B) Scope Usage (back to top...)
When you make a "controller," you pass the $scope object as an argument.
1) Arguments and Parameters (back to top...)
It's healthy to review these terms real quick.
In a function, you've got two primary entities: A "parameter" and an "argument."
A "parameter" is this:
function(parameter, paramater) {
do something...
return something
}
An "argument" is a specific value that's passed in as one of the parameters.
So, if you've got something like this:
function id(x) { // "x" is a parameter
return x;
}
When you invoke / call that function, you would pass a variable into the function in order for it to do what's designed to accomplish. In this instance, you might pass a word into it like this:
function id('hello');
You would get "hello" back. The argument in this case, is "hello."
For more info, click here.
Now, going to back to AngularJS, you're passing the $object property into your controller as an argument.
app.controller('personCtrl', function($scope) {
C) Root Scope (back to top...)
You have available to you something called "root scope" which looks like this:
<body ng-app="myApp">
The rootScope's favorite color is: {{color}}.
<div ng-controller="myCtrl">
The scope of the controller's favorite color is: {{color}}.
</div>
<script>
var app=angular.module('myApp', []);
app.run(function($rootScope) {
$rootScope.color='blue';
});
app.controller('myCtrl', function($scope) {
$scope.color="red";
});
</script>
</body>
- currency Format a number to a currency format
- date Format a date to a specified format
- filter Select a subset of items from an array
- json Format an object to a JSON string
- limitTo Limits an array/string, into a specified number of elements/characters
- lowercase Format a string to lower case
- number Format a number to a string
- orderBy Orders an array by an expression
- uppercase Format a string to upper case
<ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
{{x | myFormat}}
</li>
</ul>
<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
return function(x) {
var i, c, txt = "";
for (i = 0; i < x.length; i++) {
c = x[i];
if (i % 2 == 0) {
c = c.toUpperCase();
}
txt += c;
}
return txt;
};
});
app.controller('namesCtrl', function($scope) {
$scope.names = [
'Jani',
'Carl',
'Margareth',
'Hege',
'Joe',
'Gustav',
'Birgit',
'Mary',
'Kai'
];
});
</script>
- .delete()
- .get()
- .head()
- .jsonp()
- .patch()
- .post()
- .put()
- .config: the object used to generate the request
- .data: a string, or an object, carrying the response from the server
- .headers: a function to sue to get header information
- .status: a number defining the HTTP status
- .statusText: a string defining the HTTP status
<div ng-app="myApp" ng-controller="myCtrl">
Data: {{content}}<br>
Status: {{statuscode}}<br>
StatusText: {{statustext}}
</div>
<br>The response object has a number of properties. You're seeing a snippet of some of those listed above.
<script>
var app=angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("wuddup.htm")
.then(function (response) {
$scope.content = response.data;
$scope.statuscode = response.status;
$scope.statustext = response.statusText;
});
});
</script>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
</div>
<script>
var app=angular.module("myApp", []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("customers.php")
.then(function(response)
{$scope.names = response.data.records;});
});
</script>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr ng-repeat="x in names | orderBy : 'Country'">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
</div>
<script>
var app=angular.module("myApp", []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("customers.php")
.then(function(response)
{$scope.names = response.data.records;});
});
</script>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car...</p>
<select ng-model="selectedCar">
<option></option>
<option ng-repeat="x in cars" value="{{x.model}}">{{x.model}}</option>
</select>
<h1>You selected: {{selectedCar}}</h1>
</div>
<script>
var app=angular.module("myApp", []);
app.controller('myCtrl', function($scope) {
$scope.cars=[
{model : "Ford Mustang", color : "red"},
{model : "Fiat 500", color : "white"},
{model : "Volvo XC90", color : "black"}
];
});
</script>
<p>When you use the "ng-repeat" directive to create dropdown lists, the selected value must be a string.</p>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car...</p>
<select ng-model="selectedCar" ng-options="x.model for x in cars">
</select>
<h1>You selected: {{selectedCar.model}}</h1>
<p>...and its color is: {{selectedCar.color}}!</p>
</div>
<script>
var app=angular.module("myApp", []);
app.controller('myCtrl', function($scope) {
$scope.cars=[
{model : "Ford Mustang", color : "red"},
{model : "Fiat 500", color : "white"},
{model : "Volvo XC90", color : "black"}
];
});
</script>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car...</p>
<select ng-model="selectedCar" ng-options="x for (x, y) in cars">
</select>
<h1>You selected: {{selectedCar}}</h1>
<h1>...the color is: {{selectedCar.model}}</h1>
<h1>...and the color is {{selectedCar.color}}</h1>
</div>
<script>
var app=angular.module("myApp", []);
app.controller('myCtrl', function($scope) {
$scope.cars = {
car01 : {brand : "Ford", model : "Mustang", color : "red"},
car02 : {brand : "Fiat", model : "500", color : "white"},
car03 : {brand : "Volvo", model : "XC90", color : "black"}
};
});
</script>
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
require_once("term_class_pdo.php");
$current_discipline="";
$new_list= new TermAdmin;
$term_display=$new_list->term_list();
$output="";
foreach($term_display as $term)
{
if($output !="")
{
{$output.= ", ";}
}
$output.= '{"disicpline": "' . stripslashes($term['discipline']) .'", ';
$output.= '"term": "' .stripslashes($term['term']) .'", ';
$output.='"definition"; "'. stripslashes($term['definition']).'"}';
}
$output = '{"records": ['.$output.']}';
echo $output;
?>
{"records": [{"disicpline": "JQuery", "term": "Boilerplate", "definition"; "A Plugin is a JQuery object that does something cool. When you determine that you want to build your own plugin, which is very likely, you'll use what's called a "Boilerplate" to encapsulate your code so any potential redundancy between the syntax you use and code that exists elsewhere in your app doesn't conflict with one another.
<br><br>
This is fairly verbose, but it's not that difficult. Just buckle up...
<br><br>
// the semi-colon before function invocation is a safety net against concatenated<br>
// scripts and/or other plugins which may not be closed properly.<br>
<br><br>
<b>;(function ( $, window, undefined ) {</b>
// undefined is used here as the undefined global variable in ECMAScript 3 is<br>
// mutable (ie. it can be changed by someone else). undefined isn't really being<br>
// passed in so we can ensure the value of it is truly undefined. In ES5, undefined<br>
// can no longer be modified.<br>
// window and document are passed through as local variables rather than globals<br>
// as this (slightly) quickens the resolution process and can be more efficiently<br>
// minified (especially when both are regularly referenced in your plugin).<br>
<br><br>
// Create the defaults once<br>
<b>var pluginName = "defaultPluginName",<br>
document = window.document,<br>
defaults = {<br>
propertyName: "value"<br>
};</b><br><br>
The first thing you should notice is that these variable are defined outside of any functions � the IIFE doesn�t count � which limits the number of instances to 1 (as opposed to 1 for each time the plugin is called or a plugin object is instantiated) and it makes them available to everything within the IIFE. The first variable is pluginName, which should be the name of the function that you are extending jQuery with. It�s referenced on lines 32, 45, 47, and 48. This allows you to change the name of your plugin in one place rather than in all 4 of those places mentioned (and more places if you need to reference it within the code you write). The next variable is document, which is just a reference to the document � often used in jQuery plugins � which allows it to be shortened by minifiers again. The final variable is defaults. Most plugins give users options that they can send in to the plugin and this variable contains the default values for each of the options you offer.
<br><br>
// The actual plugin constructor<br>
<b> function Plugin( element, options ) {<br>
this.element = element;</b><br><br>
// jQuery has an extend method which merges the contents of two or<br>
// more objects, storing the result in the first object. The first object<br>
// is generally empty as we don't want to alter the default options for<br>
// future instances of the plugin<br>
<b>this.options = $.extend( {}, defaults, options) ;<br>
this._defaults = defaults;<br>
this._name = pluginName;<br>
this.init();<br>
}</b>
<br><br>
This is the constructor for the object that will be doing all the heavy lifting in the plugin. The constructor is pretty minimal, mostly just creating a few instance properties and then leaving the rest up to init. Walking through, this.element holds the DOM element that this plugin is supposed to manipulate, this.options holds an object with all of the options that the user sent in and any defaults that weren�t overridden by the user. The rest are pretty self-explanatory.
<br><br>
<b>Plugin.prototype.init = function () {<br>
// Place initialization logic here<br>
// You already have access to the DOM element and the options via the instance,<br>
// e.g., this.element and this.options<br>
};</b><br><br>
The init function where all the logic associated with this plugin�s initialization should be placed. <br><br>
And finally...<br><br>
// A really lightweight plugin wrapper around the constructor,<br>
// preventing against multiple instantiations<br>
<b>$.fn[pluginName] = function ( options ) {<br>
return this.each(function () {<br>
if (!$.data(this, 'plugin_' + pluginName)) {<br>
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));<br>
}<br>
});<br>
}</b>"}, {"disicpline": "JQuery", "term": "CDN", "definition"; "When you load the JQuery library into your page, rather than have the actual library sitting on your personal server, you'll refer to it using a CDN.
<br><br>
CDN stands for Content Development Network. It's a series of servers scattered around the world. When you use a URL such as this:
<br><br>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<br><br>
...you're system is defaulting to the closest server in the network to access the JQuery library.
<br><br>
Click <a href="http://www.webopedia.com/TERM/C/CDN.html" target="_blank">here</a> for more info."}, {"disicpline": "JQuery", "term": "Constructor", "definition"; "A constructor is used to for initializing new objects. In really simplistic terms, it looks like this:
<br><br>
function Account () {<br>
<i>your logic</i><br>
}<br><br>
// This is the use of the Account constructor to create the userAccount object.
<br><br>
var userAccount = new Account (); //notice the use of the word "new""}, {"disicpline": "JQuery", "term": "DOM", "definition"; "DOM stands for "Document Object Model."
<br><br>
In an HTML document, you've got any one of number of elements; <div>, <tr>, <span> etc. The way those things are represented and organized on a page is the "Document Object Model." In JQuery, that's significant because you're usually interacting with specific elements within the DOM and it's because of the structure and organization of the DOM that JQuery can be so useful."}, {"disicpline": "JQuery", "term": "Function Expression vs Function Declaration and IIFE", "definition"; "In JavaScript, there are two basic ways of invoking a function. The most common way is "declaration..."
<br><br>
function myFunction() { <i>logic here</i> }
<br><br>
The other way to do is referred to as an "expression" where the function is part of a larger chunk of syntax. Like this:
<br><br>
var somethingSpecial = function() { <i>logic here</i> }
<br><br>
You can also assign a function to a property (notice the placement of the curly braces);
<br><br>
var myObject = {
<br><br>
myFunction: function) {<i>logic here</i> }
<br><br>
}<br><br>
Regardless if you're using the Definition or the Expression approach, in both instances you're having to instantiate it with a var or some kind of systemic step. <br><br>
With IIFE (Immediately Invoked Function Expressions), you're "immediately" invoking the functionality. So, just as soon as the page is accessed, BOOM! All that code kicks on and you're up and running.
The big thing, however, is that with IIFE you're able to isolate your code in a way where you can use "var" throughout and not worry about how "var" is used in other sections of your app causing name collisions.
The code you would use for that would look like this:
(function() {
<i>logic here</i>
})();
Click <a href="http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html" target="_blank">here</a> for more information. And here's another <a href="https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/" target="_blank">link</a> as well..."}, {"disicpline": "JQuery", "term": "IIFE", "definition"; "IIFE stands for "Immediately Invoked Function Expression. It's an anonymous function (no name attached to it) that is wrapped inside of a set of parentheses and called (invoked) immediately. This is some of the foundational logic that the Boilerplate dynamic is built upon.
For more info, click <a href="http://gregfranko.com/blog/i-love-my-iife/" target="_blank">here</a>."}, {"disicpline": "JQuery", "term": "JQuery", "definition"; "Jquery is a library of JavaScript. What would otherwise represent mountains of code is now simply referred to in the context of JQuery functions.
<br><br>
You'll load the JQuery library in your header like this:
<br><br>
<script src="jquery-3.2.1.min.js"></script>
<br><br>
Now, you've got access to all kinds of functionality that would otherwise require thousands of lines of code."}, {"disicpline": "JQuery", "term": "min", "definition"; ""min" stands for "minify."
<br><br>
The Jquery library with all of the expected white space and line breaks equates to a pretty big file. "min" removes all of the white space. It's really hard to read, but it takes up less room."}, {"disicpline": "JQuery", "term": "Object", "definition"; "A JQuery object is a var, but a whole lot more.
<br><br>
For example, if you have 3 TEXTAREA elements on the page and you do this:
<br><br>
var j = $('textarea');
<br><br>
then this j jQuery object will contain these properties:
<br><br>
0 - reference to the first TEXTAREA element<br>
1 - reference to the second TEXTAREA element<br>
2 - reference to the third TEXTAREA element<br>
length - which is 3<br>
context - reference to the document object<br>
selector - which is 'textarea<br>'"}, {"disicpline": "JQuery", "term": "Plugin", "definition"; "A plugin is a piece of JQuery code that does something cool. There's a whole registry of them that you can access but sometimes you want to create your own plugin in that you're able to create a piece of functionality once and then use it repeatedly without having to rewrite it every time.
<br><br>
Let's say we want to create a plugin that makes text within a set of retrieved elements green. All we have to do is add a function called greenify to $.fn and it will be available just like any other jQuery object method.
<br><br>
$.fn.greenify = function() {<br>
this.css( "color", "green" );<br>
};<br><br>
$( "a" ).greenify(); // Makes all the links green.<br><br>
Cool! Click <a href="https://learn.jquery.com/plugins/basic-plugin-creation/" target="_blank">here</a> for more info."}, {"disicpline": "JQuery", "term": "Property", "definition"; "A Property is a variable defined within a function.
<br><br>
Click <a href="https://www.w3schools.com/js/js_properties.asp" target="_blank">here</a> for more detailed info."}, {"disicpline": "JQuery", "term": "Scope", "definition"; "<i>Scope</i> in JavaScript is similar to "visibility" in OOP in that it refers to accessibility within your app.
<br><br>
<u>Global</u> means that whatever it is that you're creating or defining is available and accessible anywhere, anytime throughout your entire application. An example would be:
<br><br>
// global scope<br>
var name = 'Todd';<br><br>
<u>Local</u> means that the entity in question is available only within the function it was created in. Like this:
<br><br>
//global scope out here...<br><br>
var myFunction = function () {<br>
//local scope in here<br>
var name = 'Todd';<br>
console.log(name); // Todd<br>
};<br><br>
// Uncaught ReferenceError: name is not defined because you're referring to a var that is "local" in scope
console.log(name);
For more info, click <a href="https://toddmotto.com/everything-you-wanted-to-know-about-javascript-scope/" target="_blank">here</a>"}, {"disicpline": "JQuery", "term": "Selector", "definition"; "A Selector in JQuery is what you're using systemically to grab a particular element within the DOM, like a <div> or a specific field that has a unique id.
<br><br>
Like this:
<br><br>
var theDiv = $("#theDiv");
<br><br>
Now, remember, "theDiv" is a JQuery object which is very cool in that it's more than just a variable. It has properties and other systemic features that can be very cool when it comes to programming.
<br><br>
Click <a href="http://tutorials.jenkov.com/jquery/selectors.html" target="_blank">here</a> for more info."}, {"disicpline": "JQuery", "term": "use strict", "definition"; ""use strict" is a piece of code that tells the system not to be sloppy in the way it processes your code. In this way, you're able to avoid some errors that might otherwise occur if the system is being too forgiving.
<br><br>
Strict mode makes it easier to write "secure" JavaScript.
<br><br>
Strict mode changes previously accepted "bad syntax" into real errors.
<br><br>
As an example, in normal JavaScript, mistyping a variable name creates a new global variable. In strict mode, this will throw an error, making it impossible to accidentally create a global variable.
<br><br>
In normal JavaScript, a developer will not receive any error feedback assigning values to non-writable properties.
<br><br>
In strict mode, any assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object, will throw an error.
<br><br>
Click <a hrer="https://www.w3schools.com/js/js_strict.asp" target="_blank">here</a> for more info."}, {"disicpline": "Laravel", "term": "Installation", "definition"; "definition"}, {"disicpline": "NET", "term": "API", "definition"; ""Application Programming Interface." A fancy term to describe all of the builiding blocks that combine to form a computer program of some sort. <br /><br />
<div class="quote">In computer programming, an application programming interface (API) is a set of subroutine definitions, protocols, and tools for building application software. In general terms, it's a set of clearly defined methods of communication between various software components.<br /><br /> What makes API such an advantage is the way it serves as a "one stop shop" for your business logic so you're not having to reinvent the wheel for every browser, OS etc.</div>"}, {"disicpline": "NET", "term": "double", "definition"; "<em>double</em> refers to numbers with decimal points."}, {"disicpline": "NET", "term": "floating point", "definition"; "Numbers in the computer world are stored as Binary values. In Binary (1's and 0's), you've got a decimal point that "floats." It's not like your typical decimal point in the way it affects the precision of the number. Rather, it's defining the number itself.<br /><br />For example, the number "4" could potentially look like this as a Binary value: 0000101100. The placement of a decimal point affects the value of that number in whole integers. Compare that to a regular decimal point where you're reflecting precision."}, {"disicpline": "NET", "term": "HTTP", "definition"; "Hypertext Transport Protocol. This is the set of rules and protocols the web uses to transport information over the web.<br /><br />
<div class="quote">HTTP (Hypertext Transfer Protocol) is the set of rules for transferring files (text, graphic images, sound, video, and other multimedia files) on the World Wide Web. As soon as a Web user opens their Web browser, the user is indirectly making use of HTTP. HTTP is an application protocol that runs on top of the TCP/IP suite of protocols (the foundation protocols for the Internet) (<a href="http://searchwindevelopment.techtarget.com/definition/HTTP" target="_blank">techtarget</a>). <br /><br /> Basically, you're looking at a hierarchy of digital platforms that combine to provide a web based experience. It looks like this: <br /><br />
<div style="text-align: center;">TCP / IP (<a href="http://searchnetworking.techtarget.com/definition/TCP-IP" target="_blank">Transport Control Protocol / Internet Protocol</a>) -> HTTP -> HTML</div>
</div>"}, {"disicpline": "NET", "term": "JSON", "definition"; "Javascript Object Notation. It's Javascript's way of packaging data... <br /><br />
<div class="quote">JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. (<a href="http://json.org" target="_blank">JSON.org</a>)</div>"}, {"disicpline": "NET", "term": "LAMBA", "definition"; "This is something you'll encounter from time to time as part of the "app.run" portion of the Configure Construct in your Startup Class. <a href="https://www.codeproject.com/tips/298963/understand-lambda-expressions-in-minutes" target="_blank">Code Project</a> defines it like this: <br /><br />
<div class="quote">A lambda expression is an anonymous function and it is mostly used to create delegates in LINQ. Simply put, it's a method without a declaration, i.e., access modifier, return value declaration, and name. <br /><br /> Convenience. It's a shorthand that allows you to write a method in the same place you are going to use it. Especially useful in places where a method is being used only once, and the method definition is short. It saves you the effort of declaring and writing a separate method to the containing class.</div>"}, {"disicpline": "NET", "term": "LINQ", "definition"; "LINQ (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Microsoft .NET-based programming languages."}, {"disicpline": "NET", "term": "Object", "definition"; "An Object is an Instance of a Class. Here's the hierarchy:<br /><br />Class -> Instance -> Object<br /><br /><strong>Class</strong> - a mountain of functionality that is off stage.<br /><strong>Instance</strong> - creating a digital placeholder for that "mountain of functionality" that equates to me bringing all of that on to the stage.<br /><strong>Object</strong> - engaging that "mountain of functionality" in a way that translates to an actual task or value.<br /><br />You'll often see "Instance" and "Object" used interchangably. That's not a criminal thing to do but be aware of how "object" refers to a unique "instance" of a class because of the way an object has a the functionality in that Class actually <span style="text-decoration: underline;">doing</span> something."}, {"disicpline": "NET", "term": "REST", "definition"; "This is similiar to the protocol that you see in apps such as Code Igniter. The URL of the site isn't your typical ".htm" or ".php." Rather, it's a cue represented by some text that tells your program what to do. You see this a lot with the .NET architecture you're using. <br /><br />
<div class="quote">REST stands for "Representational State Transfer" and it is an architectural pattern for creating an API that uses HTTP as its underlying communication method. REST was originally conceived by Roy Fielding in his 2000 dissertation paper entitled "Architectural Styles and the Design of Network-based Software Architectures", chapter 5 cover REST specifically: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm <br /><br /> Almost every device that is connected to the internet already uses HTTP; it is the base protocol that the internet is built on which is why it makes such a great platform for an API. (<a href="https://blogs.msdn.microsoft.com/martinkearn/2015/01/05/introduction-to-rest-and-net-web-api/" target="_blank">microsoft.com</a>)<br /><br /> You can see this referenced as one of several options a Microsoft Developer meight consider, as far as the infrastructure they would build atop the <a href="#soap">SOAP</a> philosophical foundation.</div>"}, {"disicpline": "NET", "term": "Service Layer", "definition"; "<a href="images/service_layer.jpg" target="_blank"><img style="float: right;" src="images/service_layer.jpg" alt="" width="192" height="205" border="0" /></a>The "layer" that exists between the client and the data that client is interacting with in the context of their visit to your website."}, {"disicpline": "NET", "term": "SOAP", "definition"; "Simple Object Access Protocol. Bottom line: This allows different computer langu<a href="images/api_why.jpg" target="_blank"><img style="float: right;" src="images/api_why.jpg" alt="" width="368" height="251" border="0" /></a>ages and platforms to "talk" with one another... <br /><br />
<div class="quote">SOAP (Simple Object Access Protocol) is a messaging protocol that allows programs that run on disparate operating systems (such as Windows and Linux) to communicate using Hypertext Transfer Protocol (HTTP) and its Extensible Markup Language (XML). Since Web protocols are installed and available for use by all major operating system platforms, HTTP and XML provide an at-hand solution that allows programs running under different operating systems in a network to communicate with each other. SOAP specifies exactly how to encode an HTTP header and an XML file so that a program in one computer can call a program in another computer and pass along information. SOAP also specifies how the called program can return a response. Despite its frequent pairing with HTTP, SOAP supports other transport protocols as well. (<a href="http://searchsoa.techtarget.com/definition/SOAP" target="_blank">techtarget</a>)<br /><br /></div>
SOAP is the foundation upon which various Microsoft web paradigms have been built. All of them seek to streamline syntax as much as possible while simultaneously providing a universal way to communicate data, text and graphics to different operating systems. Among those platforms you have the following:
<ul>
<li>Web Service
<ul>
<li>It's based on SOAP and returns data in XML form.</li>
<li>It supports only HTTP protocol.</li>
<li>It is not open source but can be consumed by any client that understands xml.</li>
<li>It can be hosted only on IIS.</li>
</ul>
</li>
<li><img style="float: right;" src="images/api_because.jpg" alt="" width="342" height="144" />WCF
<ul>
<li>It is also based on SOAP and returns data in XML form.</li>
<li>It is the evolution of the web service(ASMX) and supports various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.</li>
<li>The main issue with WCF is it's tedious and extensive configuration.</li>
<li>It is not open source but can be consumed by any client that understands xml.</li>
<li>It can be hosted with in the applicaion or on IIS or using window service.</li>
</ul>
</li>
<li>WCF Rest
<ul>
<li>To use WCF as WCF Rest service you have to enable webHttpBindings.</li>
<li>It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.</li>
<li>To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files</li>
<li>Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified</li>
<li>It support XML, JSON and ATOM data format.</li>
</ul>
</li>
<li>Web API
<ul>
<li>This is the new framework for building HTTP services with easy and simple way.</li>
<li>Web API is open source an ideal platform for building REST-ful services over the .NET Framework.</li>
<li>Unlike WCF Rest service, it use the full featues of HTTP (like URIs, request/response headers, caching, versioning, various content formats)</li>
<li>It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing - all of which makes it more simple and robust.</li>
<li>It can be hosted with in the application or on IIS.</li>
<li>It has a lightweight architecture and is good for devices which have limited bandwidth like smart phones.</li>
<li>Responses are formatted by Web API's MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.</li>
</ul>
</li>
</ul>
When to choose either WCF or WEB API
<ul>
<li>Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.</li>
<li>Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.</li>
<li>Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).</li>
<li>Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets. (<a href="http://www.dotnettricks.com/learn/webapi/difference-between-wcf-and-web-api-and-wcf-rest-and-web-service" target="_blank">dotnettricks</a>)</li>
</ul>"}, {"disicpline": "NET", "term": "WCF", "definition"; "One of several platforms that Microsoft offers that's built upon the SOAP philosophical foundation. See the "<a href="#soap">SOAP</a>" link at the top of this page."}, {"disicpline": "NET", "term": "XML", "definition"; "Extensible Markup Language. "Extensible" means, "capable of being extended." To understand XML, you've got to go back to HTML and unpack what HTML stands for. "HTML stands for "Hypertext Markup Language." "Markup Language" refers to a series of symbols or characters that are inserted in the context of a website or a Word Processing program that programmatically dictate how that text is to appear. <strong><<strong>, for example, is inserted prior to a word to cue the system that it needs to display a text in bold. <br /><br /> XML does the same kind of thing with data. And what makes that so useful is that it not only "communicates" data, it also communicates how that data is to be formatted... <br /><br />
<div class="quote">XML code, a formal recommendation from the World Wide Web Consortium (W3C), is similar to Hypertext Markup Language (HTML). Both XML and HTML contain markup symbols to describe page or file contents. HTML code describes Web page content (mainly text and graphic images) only in terms of how it is to be displayed and interacted with. <br /><br /> XML data is known as self-describing or self-defining, meaning that the structure of the data is embedded with the data, thus when the data arrives there is no need to pre-build the structure to store the data; it is dynamically understood within the XML. The XML format can be used by any individual or group of individuals or companies that want to share information in a consistent way. XML is actually a simpler and easier-to-use subset of the Standard Generalized Markup Language (SGML), which is the standard to create a document structure. (<a href="http://searchsoa.techtarget.com/definition/XML" target="_blank">techtarget</a>)</div>"}, {"disicpline": "Networking", "term": "file:// scheme", "definition"; "You have the option of using "file://" as opposed to "http://" in the context of your web address syntax, but you will generally use "file://" when you're retrieving files from your computer or drives that are mapped to your computer. In other words, you're not venturing out into the world wide web (www) to get your content.
Click <a href="https://en.wikipedia.org/wiki/File_URI_scheme" target="_blank">here</a> for more info."}, {"disicpline": "Networking", "term": "IP address", "definition"; ""IP" stands for "Internet Protocol." When you're talking about an "IP address," you're referring to the numerical label that's put on every computer that's connected to a network. That could be a local network or it could be a server on the web. Everything has its own IP and that's what allows it to communicate and interact with other computers.
Click <a href="http://whatismyipaddress.com/ip-facts" target="_blank">here</a> for more info."}, {"disicpline": "Networking", "term": "Permissions", "definition"; "Every website, every computer / server, has "permissions." Different users have different levels of accessibility and those are dictated by the network administrator.
<a href="https://www.digitalocean.com/community/questions/proper-permissions-for-web-server-s-directory" target="_blank">Digital Ocean</a> and <a href="https://support.microsoft.com/en-us/help/313075/how-to-configure-web-server-permissions-for-web-content-in-iis" target="_blank">Microsoft</a> has some good info on this topic."}, {"disicpline": "Networking", "term": "Ping", "definition"; "When you're wanting to determine whether a particular IP address is valid and there's a legitimate presence on the other side of that value, you use "ping."
Open up your command line interface and type in "ping your web address." If it's a valid site / resource, you'll get a return "package" that qualifies it as legitimate.
Click <a href="http://smallbusiness.chron.com/ping-website-cmd-53939.html" target="_blank">here</a> for more info."}, {"disicpline": "PHP", "term": "Class", "definition"; "Some use the illustration of a "blueprint." Bottom line: It's a bunch of functionality that typically includes several methods as well as some other optional "helps" like Constructors and Properties etc. <br /><br />I like to think of it as a mini-machine. It's represented by a greyed-out button that you have to activate in order for the machine to start running. You activate it by something called "instantiation." At that point, the button is no longer greyed out and you can start taking advantage of whatever functionality it's bringing to the table!<br /><br />Examples of Classes are found thoughout the samples I've included below."}, {"disicpline": "PHP", "term": "Constructor", "definition"; "A Constructor assigns some values for you automatically as soon as the Class is instantitated. So, by default you have some data established that can be used by your Class or any "children," should you position your Class to be something another Class might inherit. <br /><br />You'll need to set up some "Properties" first and then use your Constructor to assign values to those Properties.<br /><br />Here's an example:
<p><span style="color: #3366ff;">class Spreadsheet {<br /></span><span style="color: #3366ff;"> public $name; <span style="color: #008000;">//here's your property<br /></span></span><span style="color: #3366ff;"> function __construct() { <br /> $this->name="Bruce"; <span style="color: #008000;">//here's your constructor giving the value "Bruce" to your "name" property </span> <br /> echo $this->name; <br /> } <br />}<br /></span><span style="color: #3366ff;">$new_spreadsheet = new Spreadsheet();<br /><br /><span style="color: #000000;">When you run this code, you'll get "Bruce."</span></span></p>"}, {"disicpline": "PHP", "term": "Encapsulation", "definition"; "Encapsulation refers to the way in you systemically organize and protect data within a class so it's not accessible to anyone other than methods within the same class. In other words, it's how you keep your data and functionality in the yard so it doesn't go running all over the neighborhood."}, {"disicpline": "PHP", "term": "Instance", "definition"; "In order to bring the functionality represented by a Class to bear, you have to "instantiate" it. That is, you have to create a Instance of that Class. Once you do that, the "greyed out" button that was that Class is now an "active" button. <br /><br />It looks like this:<br /><br /><span style="color: #3366ff;">class NewClass {</span><br /><br /><span style="color: #3366ff;"> public function something_wonderful() {</span><br /><span style="color: #3366ff;"> </span><br /><span style="color: #3366ff;"> echo "bring it";</span><br /><span style="color: #3366ff;"> </span><br /><span style="color: #3366ff;"> }</span><br /><br /><span style="color: #3366ff;">}</span><br /><br /><span style="color: #3366ff;">$say_something=new NewClass;</span> <span style="color: #339966;">//this is an "Instance" of the NewClass class</span>"}, {"disicpline": "PHP", "term": "JQuery", "definition"; "bring it"}, {"disicpline": "PHP", "term": "MCRYPT_RIJNDAEL_128", "definition"; "You would think that MCRYPT_RIJNDAEL_256 specifies 256-bit encryption, but that is wrong. The three choices specify the block-size to be used with Rijndael encryption. They say nothing about the key size (i.e. strength) of the encryption. (Read further to understand how the strength of the AES encryption is set.)
<br><br>
The Rijndael encyrption algorithm is a block cipher.
<br><br>
<div style="border-radius:10pt; border:1px solid #cccccc; width:600px; height:auto; padding:10px; margin:auto; box-shadow:10px 10px 5px #cccccc;">A "cipher" is a computer term that refers to an algorithm for performing encryption. A "block cipher" refers an algorithm that's performed on a fixed-length group of "bits.")</div>
<br>
It operates on discrete blocks of data. Padding MUST be added such that the data to be encrypted has a length that is a multiple of the block size. (PHP pads with NULL bytes) Thus, if you specify MCRYPT_RIJNDAEL_256, your encrypted output will always be a multiple of 32 bytes (i.e. 256 bits). If you specify MCRYPT_RIJNDAEL_128, your encrypted output will always be a multiple of 16 bytes.
<br><br>
<div style="border-radius:10pt; border:1px solid #cccccc; width:600px; height:auto; padding:10px; margin:auto; box-shadow:10px 10px 5px #cccccc;">A "bit" is the smallest unit of information that a computer can store. A "byte" is a collection of bits.</div></br>
Note: Strictly speaking, AES is not precisely Rijndael (although in practice they are used interchangeably) as Rijndael supports a larger range of block and key sizes; AES has a fixed block size of 128 bits and a key size of 128, 192, or 256 bits, whereas Rijndael can be specified with key and block sizes in any multiple of 32 bits, with a minimum of 128 bits and a maximum of 256 bits. In summary: If you want to be AES compliant, always choose MCRYPT_RIJNDAEL_128.
<br><br>
<div style="border-radius:10pt; border:1px solid #cccccc; width:600px; height:auto; padding:10px; margin:auto; box-shadow:10px 10px 5px #cccccc;">AES stands for "<a href="https://www.boxcryptor.com/en/encryption/" target="_blank">Advanced Encryption Standard</a>" and is used by the NSA. You generally have two types of encryption: Aesymetric and Symetric. Aesymetric refers to the fact that you have both a public and a private key. Symetric is just one private key.</div><br>
So the first step is to create the cipher object:
<br><br>
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
<br><br>
We're using CBC mode (cipher-block chaining). Block cipher modes are detailed here: <a href="http:en.wikipedia.org/wiki/Block_cipher_modes_of_operation" target="_blank">http:en.wikipedia.org/wiki/Block_cipher_modes_of_operation</a>
<br><br>
CBC mode requires an initialization vector. The size of the IV (initializationvector) is always equal to the block-size. (It is NOT equal to the key size.) Given that our block size is 128-bits, the IV is also 128-bits (i.e. 16 bytes). Thus, for AES encryption, the IV is always 16 bytes regardless of the strength of encryption.
<br><br>
Here's some PHP code to verify our IV size:
<br><br>
$iv_size = mcrypt_enc_get_iv_size($cipher);<br>
printf("iv_size = %dn",$iv_size);
<br><br>
How do you do 256-bit AES encryption in PHP vs. 128-bit AES encryption??? The answer is: Give it a key that's 32 bytes long as opposed to 16 bytes long.
<br><br>
For example:
<br><br>
$key256 = '12345678901234561234567890123456';<br>
$key128 = '1234567890123456';
<br><br>
Here's our 128-bit IV which is used for both 256-bit and 128-bit keys.
<br><br>
$iv = '1234567890123456';
<br><br>
printf("iv: %sn",bin2hex($iv));<br>
printf("key256: %sn",bin2hex($key256));<br>
printf("key128: %sn",bin2hex($key128));<br><br>
This is the plain-text to be encrypted:
<br><br>
$cleartext = 'The quick brown fox jumped over the lazy dog';<br>
printf("plainText: %snn",$cleartext);
<br><br>
The mcrypt_generic_init function initializes the cipher by specifying both the key and the IV. The length of the key determines whether we're doing 128-bit, 192-bit, or 256-bit encryption. Let's do 256-bit encryption here:
<br><br>
if (mcrypt_generic_init($cipher, $key256, $iv) != -1)<br>
{<br>
// PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
<br><br>
$cipherText = mcrypt_generic($cipher,$cleartext );<br>
mcrypt_generic_deinit($cipher);
<br><br>
Display the result in hex.
<br><br>
printf("256-bit encrypted result:n%snn",bin2hex($cipherText));<br>
}
<br><br>
Now let's do 128-bit encryption:<br><br>
if (mcrypt_generic_init($cipher, $key128, $iv) != -1)<br>
{<br><br>
// PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
<br><br>
$cipherText = mcrypt_generic($cipher,$cleartext );<br>
mcrypt_generic_deinit($cipher);
<br><br>
// Display the result in hex.<br>
printf("128-bit encrypted result:n%snn",bin2hex($cipherText));<br<
}
<br><br>
<hr><br>
Results<br>
<hr><br><br>
You may use these as test vectors for testing your AES implementations...
<br><br>
<hr>
256-bit key, CBC mode<br>
<hr><br>
IV = '1234567890123456' <br>
(hex: 31323334353637383930313233343536)<br>
Key = '12345678901234561234567890123456' <br>
(hex: 3132333435363738393031323334353631323334353637383930313233343536)<br><br>
PlainText:<br>
'The quick brown fox jumped over the lazy dog'<br>
CipherText(hex):<br>
2fddc3abec692e1572d9b7d629172a05caf230bc7c8fd2d26ccfd65f9c54526984f7cb1c4326ef058cd7bee3967299e3
<br><br>
<hr>
128-bit key, CBC mode
<hr>
<br>
IV = '1234567890123456' <br>
(hex: 31323334353637383930313233343536)<br>
Key = '1234567890123456' <br>
(hex: 31323334353637383930313233343536)<br>
PlainText:<br>
'The quick brown fox jumped over the lazy dog'<br>
CipherText(hex):<br>
f78176ae8dfe84578529208d30f446bbb29a64dc388b5c0b63140a4f316b3f341fe7d3b1a3cc5113c81ef8dd714a1c99<br>"}, {"disicpline": "PHP", "term": "Object", "definition"; "Although you'll sometimes hear Instance and Object used interchangeably, there are different.<br /><br />An Instance of a Class is my having put the key in the ignition and fired it up. It's no longer a dormant piece of machinery, it's running and ready to be engaged. <br /><br />An Object is something that machine has made - it's a result of that functionality. It looks like this:<br /><br /><span style="color: #3366ff;">class NewClass { </span> <span style="color: #3366ff;"> <br /><br /> public function something_wonderful() {<br /></span> <span style="color: #3366ff;"> </span> <span style="color: #3366ff;"> <br /> echo "bring it";</span> <span style="color: #3366ff;"> </span> <span style="color: #3366ff;"> <br /> <br /> }</span> <br /><br /><span style="color: #3366ff;">}</span> <span style="color: #3366ff;"> <br /><br />$say_something=new NewClass;</span> <span style="color: #339966;">//this is an "Instance" of the NewClass class</span> <span style="color: #3366ff;">$shout = $say_something->something_wonderful();</span> <span style="color: #339966;">//$shout is an Object of the NewClass Class </span>"}, {"disicpline": "PHP", "term": "PDO", "definition"; "PHP Data Objects. There are several advantages to using PDO. Here are a couple: <br /><br /> <span style="text-decoration: underline;">Database Abstraction Layer</span> - an API that allows you to connect with any one of a number of databases. <br /><br /> <span style="text-decoration: underline;">Prepared Statements</span> - here you're executing your SQL without any data battached to it. This is how you avoid SQL Injection. <br /><br /> So, this: <br /><br /> <span style="color: #3366ff;">$sql = "SELECT * from users where email='$email' AND status='$status'"</span> <br /><br /> Becomes this: <br /><br /> <span style="color: #3366ff;">$sql="SELECT * FROM users where email=? AND status=?";</span> <br /><br /> ...and then you would run the EXECUTE method of this object, so it would look like this: <br /><br /> <span style="color: #3366ff;">$stmt=$pdo->prepare("SELECT * FROM users WHERE email=? AND status=?"); $stmt->execute(['email=>$email, 'status=>$status]); $user=$stmt->fetch();</span>"}, {"disicpline": "PHP", "term": "Scope", "definition"; "Scope is a term that refers to the extent to which a variable makes sense. In other words, how logical does that variable appear to another method - one that didn't create the variable to begin with? <br /><br /><br />You've got four different types of "scope..."<br /><br />local<br />function<br />global<br />superglobal<br /><br />Scope is similiar to Visibility, but with Visibility you've got <br /><br />public<br />protected<br />private<br /><br />So, there is a difference in that scope is more about variables whereas you'll see visibility describing the accessibility of methods and properties more so than variables. <br /><br />One definition that struck me as being especially clear was, "Scope can be defined as the range of availability a variable has to the program in which it is declared." (<a href="https://www.tutorialspoint.com/php/php_static_variables.htm" target="_blank">tutorialspoint.com</a>)"}, {"disicpline": "PHP", "term": "Static", "definition"; "On occasion, in addition to seeing a variable or a method's visibility qualified in terms of either private, protected or public, you may also see it referenced as "static."
"Static" is a handy tool in that it doesn't have to be instantiated. It can directly accessed using the Scope Resolution Operator(::). For example:
$con=DatabaseFactory::CreateLegacyAegisHealthConnection();
CreateLegacyAegisHealthConnection() is a static function in the DatabaseFactory Class. I didn't have to write:
$new_con=new DatabaseFactory();
$new_connection=$new_con->CreateLegacyHealthConnection().
I just used the Scope Resolution Operator and, "BAM!" it's right there!
Same dynamic applies to both Methods and Properties."}, {"disicpline": "PHP", "term": "Superglobal Variable", "definition"; "<p>Global variables are accessible from any class, method or function from anywhere in the application. Public, Private, Protected, Child, Parent - doesn't matter. If it's a Superglobal variable, you can grab it and use it and you only have to define it once.<br /><br />An example would be $_SESSION. That's considered a Superglobal variable in that PHP knows what $_SESSION is. You still have to give it a value, but you don't have to "define" $_SESSION anymore than you have to "define" $_POST or $_GET. PHP knows what those variables are. Again, you still have to give them a value, but systemically, PHP is not looking for that variable, it already knows what it is. <br /><br />You have the same kind of utility available to you with a "Global" variable, but, unlike a Superglobal variable, you have to define it. Whereas $_SESSION is understood by PHP, $george, on the other hand, is a total mystery. <br /><br />$george could be your database connection, but in order to give it "wings" so it can fly freely throughout your app, you have to make it a global variable like this:<br /><br />Here's your database connection script:<br /><br /><span style="color: #3366ff;">$mysqli = new mysqli($host,$user,$password,$database);</span><br /><span style="color: #3366ff;"> if($mysqli->connect_errno) { </span><br /><span style="color: #3366ff;">$err="CONNECT FAIL: " </span><br /><span style="color: #3366ff;">.$mysqli->connect_errno </span><br /><span style="color: #3366ff;">. ' ' </span><br /><span style="color: #3366ff;">.$mysqli->connect_error ; </span><br /><span style="color: #3366ff;">trigger_error($err, E_USER_ERROR); </span><br /><span style="color: #3366ff;">}</span><br /><br />Now here's my class:<br /><br /><span style="color: #3366ff;">class List {</span><br /><span style="color: #3366ff;"> </span><br /><span style="color: #3366ff;"> public spreadsheet () {</span><br /> <span style="color: #3366ff;">global <strong><span style="color: #ff0000;">$mysqli;</span></strong></span><br /><span style="color: #3366ff;"> $sql="select * from table";</span><br /><span style="color: #3366ff;"> $query=<span style="color: #ff0000;"><strong>$mysqli</strong>-></span>query($sql);</span><br /><br /><span style="color: #3366ff;"> }</span><br /><br /><span style="color: #3366ff;">}</span><br /><br />I've just told my code to go look for $mysqli. It could be anywhere, but by prefacing $mysqli with "global," I'm giving my code permission to go and look anywhere and everywhere for the $mysqli variable.</p>"}, {"disicpline": "PHP", "term": "Visibility", "definition"; "Visibily is something similiar to Scope, but it's more for methods and properties. <br /><br />There are three types of visibility which are described below:<br /><br /><span style="color: #0000bb;"><span style="font-family: Courier New;"><!--?php </span--></span><span style="font-family: Courier New;"><span style="color: #ff8000;">/** * Define MyClass */ <br /><br /></span><span style="color: #007700;">class </span></span><span style="color: #0000bb;"><span style="font-family: Courier New;">MyClass </span></span><span style="font-family: Courier New;"><span style="color: #007700;">{ <br /><br />public </span><span style="color: #0000bb;">$public </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'Public'</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br />protected </span><span style="color: #0000bb;">$protected </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'Protected'</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br />private </span><span style="color: #0000bb;">$private </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'Private'</span></span><span style="font-family: Courier New;"><span style="color: #007700;">;<br /> <br /> function </span><span style="color: #0000bb;">printHello</span></span><span style="font-family: Courier New;"><span style="color: #007700;">(){ <br /> echo </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">public</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br /> echo </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">protected</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br /> echo </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">private</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br /> } <br />}<br /></span><span style="color: #0000bb;"><br />$obj </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">MyClass</span></span><span style="font-family: Courier New;"><span style="color: #007700;">(); <br />echo </span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">-></span><span style="color: #0000bb;">public</span><span style="color: #007700;">; </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Works <br /></span><span style="color: #007700;">echo </span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">-></span><span style="color: #0000bb;">protected</span><span style="color: #007700;">; </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Fatal Error <br /></span><span style="color: #007700;">echo </span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">-></span><span style="color: #0000bb;">private</span><span style="color: #007700;">; </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Fatal Error <br /></span><span style="color: #0000bb;">$obj</span><span style="color: #007700;">-></span><span style="color: #0000bb;">printHello</span><span style="color: #007700;">(); </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Shows Public, Protected and Private<br /> <br />/** * Define MyClass2 */ <br /><br /></span><span style="color: #007700;">class </span><span style="color: #0000bb;">MyClass2 </span><span style="color: #007700;">extends </span></span><span style="color: #0000bb;"><span style="font-family: Courier New;">MyClass </span></span><span style="color: #007700;"><span style="font-family: Courier New;">{ <br /></span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// We can redeclare the public and protected method, but not private <br /><br /> </span><span style="color: #007700;">public </span><span style="color: #0000bb;">$public </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'Public2'</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br /> protected </span><span style="color: #0000bb;">$protected </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'Protected2'</span></span><span style="font-family: Courier New;"><span style="color: #007700;">;<br /> <br /> function </span><span style="color: #0000bb;">printHello</span></span><span style="font-family: Courier New;"><span style="color: #007700;">(){ <br /> echo </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">public</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br /> echo </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">protected</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br /> echo </span><span style="color: #0000bb;">$this</span><span style="color: #007700;">-></span><span style="color: #0000bb;">private</span></span><span style="font-family: Courier New;"><span style="color: #007700;">; <br /> } <br />}<br /></span><span style="color: #0000bb;"><br />$obj2 </span><span style="color: #007700;">= new </span><span style="color: #0000bb;">MyClass2</span></span><span style="font-family: Courier New;"><span style="color: #007700;">(); <br />echo </span><span style="color: #0000bb;">$obj2</span><span style="color: #007700;">-></span><span style="color: #0000bb;">public</span><span style="color: #007700;">; </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Works <br /></span><span style="color: #007700;">echo </span><span style="color: #0000bb;">$obj2</span><span style="color: #007700;">-></span><span style="color: #0000bb;">protected</span><span style="color: #007700;">; </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Fatal Error <br /></span><span style="color: #007700;">echo </span><span style="color: #0000bb;">$obj2</span><span style="color: #007700;">-></span><span style="color: #0000bb;">private</span><span style="color: #007700;">; </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Undefined </span><span style="color: #0000bb;">$<br /><br />obj2</span><span style="color: #007700;">-></span><span style="color: #0000bb;">printHello</span><span style="color: #007700;">(); </span></span><span style="font-family: Courier New;"><span style="color: #ff8000;">// Shows Public2, Protected2, Undefined<br /><br /></span><span style="color: #0000bb;">?></span> <br /><br /><strong><img style="float: right;" src="/images/properties.jpg" alt="" width="300" height="300" /><span style="font-family: arial,helvetica,sans-serif;">public:</span></strong><span style="font-family: arial,helvetica,sans-serif;"> Public properties and methods can be accessed anywhere in a script after the object has been instantiated</span><br /><br /><span style="font-family: arial,helvetica,sans-serif;"><strong>protected:</strong> Protected properties and methods can be accessed only within the class that defines them, parent classes, or inherited classes</span><br /><br /><span style="font-family: arial,helvetica,sans-serif;"><strong>private:</strong> Private properties and methods can only be accessed by the class that defines them</span><br /></span></span>"}]}
- ng-blur
- ng-change
- ng-click
- ng-copy
- ng-cut
- ng-dblclick
- ng-focus
- ng-keydown
- ng-keypress
- ng-keyup
- ng-mousedown
- ng-mouseenter
- ng-mouseleave
- ng-mousemove
- ng-mouseover
- ng-mouseup
- ng-paste
- ng-mouseenter
- ng-mouseover
- ng-mousemove
- ng-mouseleave
- ng-mousedown
- ng-mouseup
- ng-click
<div class="inner_code_frame"><div ng-app="myApp" ng-controller="myController">
<h1 ng-mousemove="count = count + 1">Mouse over me!</h1>
<h2>{{count}}</h2>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myController', function($scope) {
$scope.count = 0;
});
</script>
</div>
<div ng-app="myApp" ng-controller="formController">//notice I've got one controller and one "form" for all of the different functionalities
You've got several dynamics going on here at the same time.
<br><br>
- the "First Name" field demonstrates how through the use of "data-binding" you can bind a value to a form element and refer to it elsewhere on the same page. As you enter the name in the field, you'll see it appear below...
<br><br>
<form>
First Name: <input type="text" ng-model="firstname"><br>
</form>
<br>
You entered {{ firstname }}!
<br><br>
- the checkbox can be used as a toggle switch to change the visibility of a DOM element (click on the checkbox).
<br><br>
<form>
<input type="checkbox" ng-model="myVar">
</form>
<h1 ng-show="myVar">Yo, dog!</h1>
<br>
- using radio buttons, you can display different blocks of text, which can be nice...
<br><br>
Pick a topic...
<br>
<form>
<input type="radio" ng-model="theVar" value="dogs">Dogs //same directive, but a different variable
<input type="radio" ng-model="theVar" value="tutorials">Tutorials
<input type="radio" ng-model="theVar" value="cars">Cars
</form>
<br>The ng-switch directive hides and shows HTML sections depending on the value of the radio buttons...
<br>
<div ng-switch="theVar">
<div ng-switch-when="dogs">
<h1>Dogs</h1>
<p>Welcome to the world of dogs!</p>
</div>
<div ng-switch-when="tutorials">
<h1>Learn from these examples!</p>
</div>
<div ng-switch-when="cars">
<h1>Cars</h1>
<p>Ka-chow!</p>
</div>
</div>
<br>
- you can also bind select boxes tog your application using the ng-model directive. It's the same kind of dynamic as with your radio buttons
<br>
<form>
Select a topic:
<select ng-model="bigVar"> //same directive, but a different variable
<option value=""></option>
<option value="dogs">Dogs</option>
<option value="tutorials">Tutorials</option>
<option value="cars">Cars</option>
</select>
</form>
<br>The ng-switch directive hides and shows HTML sections depending on the value of the (now) SELECT...
<br>
<div ng-switch="bigVar">
<div ng-switch-when="dogs">
<h1>Dogs</h1>
<p>Welcome to the world of dogs!</p>
</div>
<div ng-switch-when="tutorials">
<h1>Learn from these examples!</p>
</div>
<div ng-switch-when="cars">
<h1>Cars</h1>
<p>Ka-chow!</p>
</div>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('formController', function($scope) {
$scope.firstname = "John";
});
</script>
<div ng-app="myApp" ng-controller="formController">
<form novalidate>
First Name:<br>
<input type="text" ng-model="user.firstName"><br>
Last Name:<br>
<input type="text" ng-model="user.lastName">
<br><br>
<button ng-click="reset()">reset</button>
</form>
<p>form = {{user}}</p>
<p>master = {{master}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('formController', function($scope) {
$scope.master = {firstName:"John", lastName:"Doe"};
$scope.reset=function() {
$scope.user = angular.copy($scope.master);
};
$scope.reset();
});
</script>
- $untouched The field has not been touched yet
- $touched The field has been touched
- $pristine The field has not been modified yet
- $dirty The field has been modified
- $invalid The field content is not valid
- $valid The field content is valid
- $pristine No fields have been modified yet
- $dirty One or more have been modified
- $invalid The form content is not valid
- $valid The form content is valid
- $submitted The form is submitted
- Comparing Objects
- Iternating Objects
- Converting Data
angular.lowercase | converts a string to lowercase |
angular.uppercase | converts a string to uppercase |
angular.isString() | returns true if the reference is a string |
angular.isNumber() | returns true if the reference is a number |
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="/w3css/4/w3.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app="myApp" ng-controller="userCtrl">
<div class="w3-container">
<h3>Users</h3>
<table class="w3-table w3-bordered w3-striped">
<tr>
<th>Edit</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr ng-repeat="user in users">
<td>
<button class="w3-btn w3-ripple" ng-click="editUser(user.id)">✎ Edit</button>
</td>
<td>{{ user.fName }}</td>
<td>{{ user.lName }}</td>
</tr>
</table>
<br>
<button class="w3-btn w3-green w3-ripple" ng-click="editUser('new')">✎ Create New User</button>
<form ng-hide="hideform">
<h3 ng-show="edit">Create New User:</h3>
<h3 ng-hide="edit">Edit User:</h3>
<label>First Name:</label>
<input class="w3-input w3-border" type="text" ng-model="fName" ng-disabled="!edit" placeholder="First Name">
<br>
<label>Last Name:</label>
<input class="w3-input w3-border" type="text" ng-model="lName" ng-disabled="!edit" placeholder="Last Name">
<br>
<label>Password:</label>
<input class="w3-input w3-border" type="password" ng-model="passw1" placeholder="Password">
<br>
<label>Repeat:</label>
<input class="w3-input w3-border" type="password" ng-model="passw2" placeholder="Repeat Password">
<br>
<button class="w3-btn w3-green w3-ripple" ng-disabled="error || incomplete">✔ Save Changes</button>
</form>
</div>
<script src= "myUsers.js"></script>
</body>
</html>
// here's your main page
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<div ng-include="'myTable.htm'"></div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("customers.php").then(function (response) {
$scope.names = response.data.records;
});
});
</script>
</body>
// here's your "myTable.htm" file
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
// and here's your "customers.php" page...
{
"records": [
{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
},
{
"Name": "Ana Trujillo Emparedados y helados",
"City": "México D.F.",
"Country": "Mexico"
},
{
"Name": "Antonio Moreno Taquería",
"City": "México D.F.",
"Country": "Mexico"
},
{
"Name": "Around the Horn",
"City": "London",
"Country": "UK"
},
{
"Name": "B's Beverages",
"City": "London",
"Country": "UK"
},
{
"Name": "Berglunds snabbköp",
"City": "Luleå",
"Country": "Sweden"
},
{
"Name": "Blauer See Delikatessen",
"City": "Mannheim",
"Country": "Germany"
},
{
"Name": "Blondel père et fils",
"City": "Strasbourg",
"Country": "France"
},
{
"Name": "Bólido Comidas preparadas",
"City": "Madrid",
"Country": "Spain"
},
{
"Name": "Bon app'",
"City": "Marseille",
"Country": "France"
},
{
"Name": "Bottom-Dollar Marketse",
"City": "Tsawassen",
"Country": "Canada"
},
{
"Name": "Cactus Comidas para llevar",
"City": "Buenos Aires",
"Country": "Argentina"
},
{
"Name": "Centro comercial Moctezuma",
"City": "México D.F.",
"Country": "Mexico"
},
{
"Name": "Chop-suey Chinese",
"City": "Bern",
"Country": "Switzerland"
},
{
"Name": "Comércio Mineiro",
"City": "São Paulo",
"Country": "Brazil"
}
]
}
- AngularJS Animate Library: <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-animate.js"></script>
- refer to the ngAnimate module either in your application (<body ng-app="ngAnimate">) or as a dependency in your application module (var app = angular.module('myApp', ['ngAnimate']);.
Here's a basic example:
A) Basic Example (back to top...)
And here you can see the effect in real time:<!DOCTYPE html> <html lang="en"> <head> <title>Angular Tutorial</title> <link href="css/stylesheet.css" rel="stylesheet" type="text/css" /> <style> div { transition: all linear 0.5s; background-color: lightblue; height: 100px; width: 100%; position: relative; top: 0; left: 0; } .ng-hide { height: 0; width: 0; background-color: transparent; top:-200px; left: 200px; } </style> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-animate.js"></script> </head> <body ng-app="myApp"> <h1>Hide the DIV...! <input type="checkbox" ng-model="myCheck"></h1> <div ng-hide="myCheck"></div> <script> var app = angular.module('myApp', ['ngAnimate']); </script> </body> </html>
- ng-show
- ng-hide
- ng-class
- ng-view
- ng-include
- ng-repeat
- ng-if
- ng-switch
- ng-animate
- ng-hide-animate
- ng-hide-add (if the element will be hidden)
- ng-hide-remove (if the element will be showed)
- ng-hide-add-active (if the element will be hidden)
- ng-hide-remove-active (if the element will be showed)
And in real life...<!DOCTYPE html> <html lang="en"> <head> <title>Angular Tutorial</title> <link href="css/stylesheet.css" rel="stylesheet" type="text/css" /> <style> @keyframes myChange { from { height: 100px; } to { height: 0; } } div { height: 100px; background-color: lightblue; } div.ng-hide { animation: 0.5s myChange; } </style> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-animate.js"></script> </head> <body ng-app="ngAnimate"> Hide the DIV...! <input type="checkbox" ng-model="myCheck"> <div ng-hide="myCheck"></div> <script> var app = angular.module('myApp', ['ngAnimate']); </script> </body> </html>...and here it is in real life:<body ng-app="myApp"> <p><a href="#/!">Main</a></p> <a href="#!red">Red</a> <a href="#!green">Green</a> <a href="#!blue">Blue</a> <div ng-view></div> <script> var app = angular.module('myApp', ['ngRoute']); app.config(function($routeProvider) { $routeProvider .when("/", { templateUrl: "main.htm" }) .when("/red", { templateUrl : "red.htm" }) .when("/green", { templateUrl : "green.htm" }) .when("/blue", { templateUrl : "blue.htm" }) }); </script> <p>Click on the links to navigate to "red.htm", "green.htm", "blue.htm", or back to "main.htm."</p> </body>- <div ng-view></div>
- <ng-view></ng-view>
- <div class="ng-view"></div>
Here are the "Paris" and "London" htm files:<body ng-app="myApp"> <p><a href="#/!">Main</a></p> <a href="#!london">London</a> <a href="#!paris">Paris</a> <div ng-view></div> <script> var app = angular.module('myApp', ['ngRoute']); app.config(function($routeProvider) { $routeProvider .when("/", { templateUrl: "main.htm" }) .when("/london", { templateUrl : "london.htm", controller : "londonCtrl" }) .when("/paris", { templateUrl : "paris.htm", controller : "parisCtrl" }) }); app.controller("londonCtrl", function ($scope) { $scope.msg = "I love London"; // you'll see this show up in your htm as "{{msg}}" }); app.controller("parisCtrl", function($scope) { $scope.msg = "I love Paris"; }); </script> <p>Click on the links to navigate to the different pages and observe how some hard coded data from the controller dynamic can feed it into the htm page.</p> </body>...and here it is in living color:<h1>Paris</h1> <h3>Paris is the capital city of France.</h3> <p>Paris is one of the largest population centers in Europe with over 12 million inhabitants.</p> <p>{{msg}} <span style="color:green">// this text is coming from the "scope" dynamic as part of the controller</span></p> <h1>London</h1> <h3>London is the capital city of England.</h3> <p>It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p> <p>{{msg}} <span style="color:green">// this text is coming from the "scope" dynamic as part of the controller</span></p>...and in real life, it looks like this:<body ng-app="myApp"> <p><a href="#/!">Main</a></p> <a href="#!banana">Banana</a> <a href="#!tomato">Tomato</a> <div ng-view></div> <script> var app = angular.module('myApp', ['ngRoute']); app.config(function($routeProvider) { $routeProvider .when("/", { template: "<h1>Main</h1><p>Click on the links to change this content.</p>" }) .when("/banana", { template: "<h1>Banana</h1><p>Bananas are the best fruit on the planet.</p>" }) .when("/tomato", { template: "<h1>Tomotos</h1><p>Tomatos rule!</p>" }) }); </script> <p>Click on the links to navigate to the different fruits and see how each page is crafted according to the code attached to the "template" directive.</p> </body>...and in real life:<body ng-app="myApp"> <p><a href="#/!">Main</a></p> <a href="#!banana">Banana</a> <a href="#!tomato">Tomato</a> <div ng-view></div> <script> var app = angular.module('myApp', ['ngRoute']); app.config(function($routeProvider) { $routeProvider // notice there's no content for the "Main" option .when("/banana", { template: "<h1>Banana</h1><p>Bananas are the best fruit on the planet.</p>" }) .when("/tomato", { template: "<h1>Tomato</h1><p>I like spaghetti sauce so much I could eat it plain!</p>" }) .otherwise({ template: "<h1>Nothing</h1><p>Nothing has been selected!</p>" }) }); </script> <p>Click on the links to navigate to the different fruits and see how each page is crafted according to the code attached to the "template" directive.</p> </body>3) Remove Items (back to top...) We want to be able to remove items for the list, so we'll add that functionality to the module. This change will be blue...<body> <script> var app = angular.module('myShoppingList', []); app.controller("myCtrl", function($scope) { $scope.products = ["Milk", "Bread", "Cheese"]; $scope.addItem = function() { $scope.products.push($scope.addMe); } }); </script> <div ng-app="myShoppingList" ng-controller="myCtrl"> <ul> <li ng-repeat="x in products">{{x}}</li> </ul> <input ng-model="addMe"> <button ng-click="addItem()">Add</button> </div> </body>4) Error Handling (back to top...) If you try to add the same item twice or if you try to add an "empty" item, the system will crash. So, we're going to fix that by looping through what's already in the array and comparing that to what's being submitted. Here's the code. The newest additions are in orange...<script> var app = angular.module('myShoppingList', []); app.controller("myCtrl", function($scope) { $scope.products = ["Milk", "Bread", "Cheese"]; $scope.addItem = function() { $scope.products.push($scope.addMe); } $scope.removeItem = function(x) { $scope.products.splice(x, 1); //notice the command, "splice" } //notice how the loop got changed up a little bit }); </script> <div ng-app="myShoppingList" ng-controller="myCtrl"> <ul> <li ng-repeat="x in products"> {{x}} <span ng-click="removeItem($index)">×</span> </li> </ul> <input ng-model="addMe"> <button ng-click="addItem()">Add</button> </div>5) Add Some Style (back to top...) Now we add this: <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">.. ...and then add some styling elements. The end result looking pretty sharp! I'm not going to reproduce the whole script, just the stylizing part which will be highlighted in yellow...<script> var app = angular.module('myShoppingList', []); app.controller("myCtrl", function($scope) { $scope.products = ["Milk", "Bread", "Cheese"]; $scope.addItem = function() { $scope.errortext = ""; //if(!$scope.addMe) {return;} //this is another way to see if the "addMe" incoming value is blank if(!$scope.addMe) { $scope.errortext="Don't leave the field blank, please!"; } else { if($scope.products.indexOf($scope.addMe) == -1) { $scope.products.push($scope.addMe); } else { $scope.errortext = "The item is already in your shopping list!"; } } } $scope.removeItem = function(x) { $scope.errortext=""; $scope.products.splice(x, 1); } }); </script> <div ng-app="myShoppingList" ng-controller="myCtrl"> <ul> <li ng-repeat="x in products"> {{x}} <span ng-click="removeItem($index)">×</span> </li> </ul> <input ng-model="addMe"> <button ng-click="addItem()">Add</button> <p>{{errortext}}</p> </div>And here it is in real life...!<div ng-app="myShoppingList" ng-cloak ng-controller="myCtrl" class="w3-card-2 w3-margin" style="max-width:400px;"> <header class="w3-container w3-light-grey w3-padding-16"> <h3>My Shopping List</h3> </header> <ul class="w3-ul"> <li ng-repeat="x in products" class="w3-padding-16"> {{x}} <span ng-click="removeItem($index)" style="cursor:pointer;" class="w3-right w3-margin-right">x</span> </li> </ul> <div class="w3-container w3-light-grey w3-padding-16"> <div class="w3-row w3-margin-top"> <div class="w3-col s10"> <input placeholder="Add shopping items here" ng-model="addMe" class="w3-input w3-border w3-padding"> </div> <div class="w3-col s2"> <button ng-click="addItem()" class="w3-btn w3-padding w3-green">Add</button> </div> </div> <p class="w3-text-red">{{errortext}}</p> </div> </div>