29
ngularJS – Beginner Module 6/13/22 #YOOXlabsTechEvent

Angular - Beginner

Embed Size (px)

Citation preview

Page 1: Angular - Beginner

ngularJS – Beginner ModuleMay 3, 2023

#YOOXlabsTechEvent

Page 2: Angular - Beginner

(maybe )

Page 3: Angular - Beginner

Why is this project called "AngularJS"?Because HTML has Angular

bracketsWhy is the namespace called "ng"?

"ng" sounds like "Angular"Is AngularJS a library, framework, plugin or a browser extension?

AngularJS fits the definition of a framework the best

Page 4: Angular - Beginner

AngularJS Speech Topics

TemplateModuleScopeControllerModelView

Page 6: Angular - Beginner

We understand two main data binding concepts

Page 7: Angular - Beginner

Data Binding

Page 8: Angular - Beginner

Data Binding

Page 9: Angular - Beginner
Page 10: Angular - Beginner

TemplateDirective

Template structureWe will say: «Hello world!»

At a high level, Directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS's HTML compiler ($compile) to attach a specified behavior to that DOM element (e.g. via event listeners), or even to transform the DOM element and its children

Page 11: Angular - Beginner

«Hello world!!» - Template Head

<!DOCTYPE html><html lang="en" ng-app="ngBeginner" class="no-js"><head>

....

<link type="text/css" rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap-theme.min.css"> <link type="text/css" rel="stylesheet" href="assets/css/main.css">....

</head>

Page 12: Angular - Beginner

«Hello world!!» - ngAppUse this directive to auto-bootstrap an AngularJS application.

The ngApp directive designates the root element of the application and is typically placed near the root element of the page - e.g. on the <body> or <html> tags.

Page 13: Angular - Beginner

«Hello world!!» - Template Body

<body> <!-- menu -->......

<!-- Dynamic view injection --><div ng-view></div>

......

ngView is a directive that complements the $route service by including the rendered template of the current route into the main layout (index.html) file.

Page 14: Angular - Beginner

«Hello world!!» - Template Footer

......

<script src="bower_components/angular/angular.js"></script><script src="bower_components/angular-route/angular-route.js"></script><script src="app.js"></script>

......

</body></html>

Page 15: Angular - Beginner

ModuleDI – dependecy injection

Routing

Partial Template

Module defined in app.jsWe will say: «Hello world!»

Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies

Page 16: Angular - Beginner

«Hello world!!» - App.js <init>

(function (jQuery) {

'use strict';

var NGBeginner = angular .module('ngBeginner', [ 'ngRoute' ])})(jQuery);

"use strict"; Defines that JavaScript code should be executed in "strict mode"

Page 17: Angular - Beginner

«Hello world!!» - App.js <DI - Routing>NGBeginner.config(['$routeProvider', function ($routeProvider) { $routeProvider. when('/home', {

templateUrl:'views/home.html‘ }). when('/scope-hierarchy', { templateUrl:'views/scopeHierarchy.html' }).

Page 18: Angular - Beginner

ScopeHierarchy

Scope EcoSystemWe will say: «Hello world!»

Scope is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events

Page 19: Angular - Beginner

«Hello world!!» - Scope EcoSystem

Page 20: Angular - Beginner

«Hello world!!» - Scope EcoSystem

Page 21: Angular - Beginner

«Hello world!!» - Scope EcoSystem

Page 22: Angular - Beginner

ControllerDataBinding

Model

Controller and ModelWe will say: «Hello world!»

In Angular, a Controller is defined by a JavaScript constructor function that is used to augment the Angular Scope

Page 23: Angular - Beginner

«Hello world!!» - Controllers and Model

<div class="show-scope-demo"> <div ng-controller="GreetController"> Hello {{name}}! </div> <div ng-controller="ListController">

<ol> <li ng-repeat="name in names">

{{name}} from {{department}}</li>

</ol> </div></div>

Page 24: Angular - Beginner

«Hello world!!» - The code

angular .module('ngBeginner') .controller('GreetController', greetController) .controller('ListController', ['$scope', function($scope) { $scope.names = ['Igor', 'Misko', 'Vojta']; }]);

function greetController($rootScope, $scope){ $scope.name = 'World'; $rootScope.department = 'Angular';}

Page 25: Angular - Beginner

«Hello world!!» - Scope EcoSystem

Page 26: Angular - Beginner

Learning curve

NG Learning0

1

2

3

4

5

6

AngularAngular

Time

Diffi

cult

Well...and now??

Facepalm

Most awesome framwork ever!!

My code works I have no idea why

My code doesn’t works I have no idea why

My code works I have idea why

My code doesn’t works I have idea

why

Page 27: Angular - Beginner

We can say

Page 28: Angular - Beginner

ngular(ly) Happy ^_^Angular

^_^We are Angular(ly) Happy

Page 29: Angular - Beginner

QUESTIONS

#YOOXlabsTechEvent

[email protected] - @MaRiccardo