4. Angular là gì?
• AngularJS is a Javascript MVC framework created by Google to build properly architectured
and maintenable web applications.
• It’s not a JavaScript library (As they say). There are no functions which we can directly call and
use.
• It is not a DOM manipulation library like jQuery. But it uses subset of jQuery for DOM
manipulation (called jqLite).
• Focus more on HTML side of web apps.
• For MVC/MVVM design pattern
6. Philosophy
”ANGULARJS is built around the philosophy that declarative code is better than imperative code
while building UIs and wiring different components of web application together.”
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>
7. Key Features of ANGULARJS
Data-binding − It is the automatic synchronization of data between model and view components.
Scope − These are objects that refer to the model. They act as a glue between controller and view.
Controller − These are JavaScript functions that are bound to a particular scope.
Services − AngularJS come with several built-in services for example $http to make a XMLHttpRequests. These are singleton objects which are instantiated only once in app.
Filters − These select a subset of items from an array and returns a new array.
Directives − Directives are markers on DOM elements (such as elements, attributes, css, and more). These can be used to create custom HTML tags that serve as new, custom
widgets. AngularJS has built-in directives (ngBind, ngModel...)
Templates − These are the rendered view with information from the controller and model. These can be a single file (like index.html) or multiple views in one page using
"partials".
Routing − It is concept of switching views.
Model View Whatever − MVC is a design pattern for dividing an application into different parts (called Model, View and Controller), each with distinct responsibilities.
AngularJS does not implement MVC in the traditional sense, but rather something closer to MVVM (Model-View-ViewModel). The Angular JS team refers it humorously as
Model View Whatever.
Deep Linking − Deep linking allows you to encode the state of application in the URL so that it can be bookmarked. The application can then be restored from the URL to the
same state.
Dependency Injection − AngularJS has a built-in dependency injection subsystem that helps the developer by making the application easier to develop, understand, and test.
9. Advantages of AngularJS
AngularJS provides capability to create Single Page Application in a very clean and maintainable
way.
AngularJS provides data binding capability to HTML thus giving user a rich and responsive
experience
AngularJS code is unit testable.
AngularJS uses dependency injection and make use of separation of concerns.
AngularJS provides reusable components.
With AngularJS, developer write less code and get more functionality.
In AngularJS, views are pure html pages, and controllers written in JavaScript do the business
processing.
AngularJS applications can run on all major browsers and smart phones including Android and
iOS based phones/tablets.
10. Disadvantages of AngularJS
Though AngularJS comes with lots of plus points but same time we should consider the
following points −
Not Secure − Being JavaScript only framework, application written in AngularJS are not safe.
Server side authentication and authorization is must to keep an application secure.
Not degradable − If your application user disables JavaScript then user will just see the basic
page and nothing more.
24. Further topic
Directive detail options
Communication between container’s scope and directive scope
Nested scope and nested directive
Filter implementation
29. var demoApp = angular.module('demoApp', []);
What's the Array for?
var demoApp = angular.module('demoApp',
['helperModule']);
Module that demoApp
depends on
Creating a Module
30. var demoApp = angular.module('demoApp', []);
demoApp.controller('SimpleController', function ($scope) {
$scope.customers = [
{ name: 'Dave Jones', city: 'Phoenix' },
{ name: 'Jamie Riley', city: 'Atlanta' },
{ name: 'Heedy Wahlin', city: 'Chandler' },
{ name: 'Thomas Winter', city: 'Seattle' }
];
});
Define a Module
Define a Controller
Creating a Controller in a Module
31. The Role of Routes
SPA Demo
http://www.myspa.com
View1 View2
View4 View3
/view2
/view3
/view4
/view1
33. SPA Demo
http://www.myspa.com
Where do Views Go in a Page?
Dynamically loaded views are injected into the shell
page as a module loads:
<div ng-view></div>
<ng-view></ng-view>
OR
View1
34. The Role of Factories
var demoApp = angular.module('demoApp', [])
.factory('simpleFactory', function () {
var factory = {};
var customers = [ ... ];
factory.getCustomers = function () {
return customers;
};
return factory;
})
.controller('SimpleController', function ($scope,
simpleFactory) {
$scope.customers = simpleFactory.getCustomers();
});
Factory injected into
controller at runtime
39. Our job
Fiin Pro Web
Demo current stage of FiinPro.Web
http://localhost:16550/index.html
Editor's Notes
You are not in a hot trend of world
It is enough stable to follow
Many follower and large community
http://todomvc.com/examples/angularjs/#/
ViewModel: Lớp trung gian giữa View và Model. ViewModel có thể được xem là thành phần thay thế cho Controller trong mô hình MVC. Nó chứa các mã lệnh cần thiết để thực hiện data binding, command.
MVC in MVC
Imperative programmingA programming language that requires programming discipline such as C/C++, Java, COBOL, FORTRAN, Perl and JavaScript. Programmers writing in such languages must develop a proper order of actions in order to solve the problem, based on a knowledge of data processing and programming.
Declarative programmingA computer language that does not require writing traditional programming logic; Users concentrate on defining the input and output rather than the program steps required in a procedural programming language such as C++ or Java.
Declarative programming examples are CSS, HTML, XML, XSLT, RegX.
Simple: http://plnkr.co/edit/9DtXX1pOQXGucqMzq9CW?p=preview
More simple: https://jsfiddle.net/viralpatel/84gJX/?utm_source=website&utm_medium=embed&utm_campaign=84gJX