Professional Documents
Culture Documents
Interpolation và data-binding
Directives
Sử dụng filter (lọc dữ liệu)
Sử dụng form
2
INTERPOLATION
3
INTERPOLATION
Disabled:
<input type="checkbox" ng-
model="isDisabled" />
<button ng-
disabled="isDisabled">Disabled</butto
n>
4
DIRECTIVES
5
DIRECTIVES
Directives chính:
ng-app: Khởi tạo ứng dụng AngularJs
ng-init: Khởi tạo dữ liệu
ng-model: Gắn kết dữ liệu ứng dụng với các đối
tượng HTML (input, select, textarea)
6
DIRECTIVES
7
DIRECTIVES
Operation
Application
Template ng-change
ng-app ng-checked
ng-controller ng-click
ng-csp
ng-disabled ng-href
ng-hide/show ng-selected
Form ng-if
ng-mouse
ng-repeat
ng-pattern
ng-switch Binding
ng-minlength
ng-transclude
ng-maxlength
ng-view
ng-required ng-bind
ng-include
ng-list ng-model
ng-true-value ng-init
ng-false-value
ng-src
ng-options
ng-submit
ng-style
8
DIRECTIVES
.directive('myDirective', function() {
return {
template: '<h1>Chào mừng các bạn đến với FPT</h1>'
};
});
9
SỬ DỤNG FILTER (LỌC DỮ LIỆU)
10
SỬ DỤNG FILTER (LỌC DỮ LIỆU)
11
SỬ DỤNG FILTER (LỌC DỮ LIỆU)
Ví dụ
<p> Cao đẳng {{ ‘fpt’ | uppercase }} </p>
Hoặc <h1> Price: {{ price | currency }} </h1>
12
DEMO SỬ DỤNG FILTER
Filter và mảng
(function(angular) {
'use strict';
angular.module('FilterInControllerModule', []).
controller('FilterController', ['filterFilter',
function FilterController(filterFilter) {
this.array = [
{name: 'Cao đẳng'},
{name: 'FPT'},
{name: 'Polytechnic'}
];
13
DEMO SỬ DỤNG FILTER
Filter và mảng
<body ng-app="FilterInControllerModule">
<div ng-controller="FilterController as ctrl">
<div>
All entries:
<span ng-repeat="entry in ctrl.array">{{entry.name}} </span>
</div>
<div>
Entries that contain an "a":
<span ng-repeat="entry in ctrl.filteredArray">{{entry.name}}
</span>
</div>
</div>
</body>
14
DEMO SỬ DỤNG FILTER
15
LẬP TRÌNH JAVASCRIPT
BÀI 8: SỬ DỤNG ANGULARJS
FORM
17
FORM
Demo
18
FORM
19
FORM
20
FORM
<div ng-controller="ExampleController">
<form novalidate class="css-form">
<label>Name: <input type="text" ng-model="user.name" required
/></label><br />
<label>E-mail: <input type="email" ng-model="user.email" required
/></label><br />
</form> </div>
<style type="text/css">
.css-form input.ng-invalid.ng-touched { background-color: #FA787E; }
.css-form input.ng-valid.ng-touched { background-color: #78FA89; }
</style>
21
FORM
<label>E-mail:
<input type="email" ng-model="user.email" name="uEmail"
required="" /></label><br />
<div ng-show="form.$submitted || form.uEmail.$touched">
<span ng-show="form.uEmail.$error.required">Tell us your
email.</span>
<span ng-show="form.uEmail.$error.email">This is not a valid
email.</span>
</div>
22
FORM
Gender:
<label><input type="radio" ng-model="user.gender" value="male"
/>male</label>
<label><input type="radio" ng-model="user.gender" value="female"
/>female</label>
<br />
<label>
<input type="checkbox" ng-model="user.agree" name="userAgree"
required="" />
23
FORM
24
FORM
Validation
ngModelController,
ngModelController.$error
$validators ( modelValue, viewValue )
$setValidity ( true: valid, false:
invalid )
25
THAM KHẢO
26
FPT POLYTECHNIC
27