SlideShare a Scribd company logo
Angular Module
Peggy
2015-08-21
angular.module('myModule', [‘xxx']);
Dependencies
Application
NameAngularJS
Install
 In the html
<script src="angular.js">
<script src="angular-animate.js">
 Download this file from
 Google CDN - //ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-animate.js
 Bower - bower install angular-animate.js @X.Y.Z
 code.angularjs.org - //code.angularjs.org/X.Y.Z/angular-animate.js
ngAnimate
 The ngAnimate module provides support for CSS-based animations
(keyframes and transitions) as well as JavaScript-based animations via
callback hooks. Animations are not enabled by default, however, by
including ngAnimate then the animation hooks are enabled for an
Angular app.
 var myModule = angular.module('myModule', ['ngAnimate']);
ngAnimate by Css
 ng-enter class 主要用於新添加的並渲染到頁面中.
 ng-move class 主要用於當元素被移動時.
 ng-leave class主要用於被刪除時.
 starting class表示一個將要開始的動畫
 active class 表示一個將要結束的動畫
/* The starting CSS styles for the enter animation */
.fade.ng-enter
{
transition:0.5s linear all;
opacity:0;
}
/* The finishing CSS styles for the enter animation */
.fade.ng-enter.ng-enter-active
{
opacity:1;
}
<div ng-if="bool" class="fade">
Fade me in out
</div>
<button ng-click="bool=true">Fade In!</button>
<button ng-click="bool=false">Fade Out!</button>
ngAnimate by JavaScript
 By making use of the module.animation() module function we can register the ainmation.
<div ng-repeat="item in items" class="slide">
{{ item }}
</div>
myModule.animation('.slide', [function()
{
return
{
// make note that other events (like addClass/removeClass) have different function input parameters
enter: function(element, doneFn) {
jQuery(element).fadeIn(1000, doneFn);
// remember to call doneFn so that angular knows that the animation has concluded
},
move: function(element, doneFn) {
jQuery(element).fadeIn(1000, doneFn);
},
leave: function(element, doneFn) {
jQuery(element).fadeOut(1000, doneFn);
}
}
}]
ngAria
 The ngAria module provides support for common ARIA attributes that
convey state or semantic information about the application for users of
assistive technologies, such as screen readers.
 ngAria – 幫助製作 AngularJS 自定義組件的新模塊
ngAria - example
 The disabled attribute is only valid for certain elements such as button,
input and textarea. To properly disable custom element directives such as
<md-checkbox> or <taco-tab>, using ngAria with ngDisabled will also add
aria-disabled. This tells assistive technologies when a non-native input is
disabled, helping custom controls to be more accessible.
<md-checkbox ng-disabled="disabled">
<md-checkbox disabled aria-disabled="true">
ngCookies
 The ngCookies module provides a convenient wrapper for reading and
writing browser cookies.
 angular.module('app', ['ngCookies']);
 Module Components
 Service
 $cookieStore: Objects put or retrieved from this storage are automatically serialized or
deserialized by angular's toJson/fromJson.
 $cookies: Provides read/write access to browser's cookies.
 Provider
 $cookiesProvider: Change the default behavior of the $cookies service.
ngCookies - example
angular.module('cookieStoreExample', ['ngCookies'])
.controller('ExampleController', ['$cookieStore', function($cookieStore) {
// Put cookie
$cookieStore.put('myFavorite','oatmeal');
// Get cookie
var favoriteCookie = $cookieStore.get('myFavorite');
// Removing a cookie
$cookieStore.remove('myFavorite');
}]);
ngMessages
 The ngMessages module provides enhanced support for displaying
messages within templates
 Instead of relying on JavaScript code and/or complex ng-if statements
within your form template to show and hide error messages specific to the
state of an input field, the ngMessages and ngMessage directives are
designed to handle the complexity
ngMessages - example
<form name="yourForm">
<label for="yourField">名稱1</label>
<input id="yourField" type="text" ng-model="field1" name="yourField" required minlength="3" />
<div ng-if="yourForm.yourField.$error">
<!-- 需指定完整的 model -->
<div ng-if=“yourForm.yourField.$error.required”>名稱是必填</div>
<div ng-if="yourForm.yourField.$error.minlength">長度需要大於3</div>
</div>
</form>
<form name="myForm">
<label for="myField">名稱</label>
<input id="myField" type="text" ng-model="field2" name="myField" required minlength="3" />
<div ng-messages="myForm.myField.$error">
<!-- 包在 ng-messages 裡 myForm.myField.$error 的 children -->
<div ng-message=“required”>名稱是必填</div>
<div ng-message="minlength">長度需要大於3</div>
</div>
</form>
ngSanitize
 The ngSanitize module provides functionality to sanitize(清理) HTML.
angular.module('sanitizeExample', ['ngSanitize'])
.controller('ExampleController', ['$scope', '$sce', function($scope, $sce)
{
$scope.snippet = '<p style="color:blue">an htmln' +
'<em onmouseover="this.textContent='PWN3D!'">click here</em>n' + 'snippet</p>';
$scope.deliberatelyTrustDangerousSnippet = function()
{
return $sce.trustAsHtml($scope.snippet);
};
}]);
ngTouch
 The ngTouch module provides touch events and other helpers for touch-
enabled devices.
 ngClick
 A more powerful replacement for the default ngClick designed to be used on
touchscreen devices. Most mobile browsers wait about 300ms after a tap-and-
release before sending the click event.
 ngSwipeLeft, ngSwipeRight
 Specify custom behavior when an element is swiped to the left(right) on a
touchscreen device.
ngTouch - ngSwipeLeft, ngSwipeRight
 Ex. http://plnkr.co/edit/?p=preview
<div ng-show="!showActions" ng-swipe-left="showActions = true">
Some list content, like an email in the inbox
</div>
<div ng-show="showActions" ng-swipe-right="showActions = false">
<button ng-click="reply()">Reply</button>
<button ng-click="delete()">Delete</button>
</div>

More Related Content

PPTX
Backbone/Marionette recap [2015]
PDF
Introduction to Vue.js
PDF
Enjoy the vue.js
PDF
Marionette: the Backbone framework
DOCX
How routing works in angular js
PPTX
Introduction to Backbone.js & Marionette.js
PDF
Modern Web Application Development Workflow - EclipseCon Europe 2014
Backbone/Marionette recap [2015]
Introduction to Vue.js
Enjoy the vue.js
Marionette: the Backbone framework
How routing works in angular js
Introduction to Backbone.js & Marionette.js
Modern Web Application Development Workflow - EclipseCon Europe 2014

What's hot (20)

PDF
Angular js routing options
PPTX
How to Build SPA with Vue Router 2.0
PDF
Advanced Tips & Tricks for using Angular JS
ODP
An Introduction to Vuejs
PDF
Steps to create image carousel by using angularjs
PPTX
Building an End-to-End AngularJS Application
PPTX
Introduction to Angularjs
PDF
Vue, vue router, vuex
PPTX
Vue business first
KEY
AngularJS for designers and developers
PPTX
ME vs WEB - AngularJS Fundamentals
PDF
Introducing Rendr: Run your Backbone.js apps on the client and server
PDF
Backbone js
PDF
Angularjs - lazy loading techniques
PPTX
Angular Lazy Loading and Resolve (Route Resolver)
PPTX
Angular js
PDF
Building a Startup Stack with AngularJS
PDF
An introduction to Vue.js
PDF
AngularJS: an introduction
PPTX
Practical AngularJS
Angular js routing options
How to Build SPA with Vue Router 2.0
Advanced Tips & Tricks for using Angular JS
An Introduction to Vuejs
Steps to create image carousel by using angularjs
Building an End-to-End AngularJS Application
Introduction to Angularjs
Vue, vue router, vuex
Vue business first
AngularJS for designers and developers
ME vs WEB - AngularJS Fundamentals
Introducing Rendr: Run your Backbone.js apps on the client and server
Backbone js
Angularjs - lazy loading techniques
Angular Lazy Loading and Resolve (Route Resolver)
Angular js
Building a Startup Stack with AngularJS
An introduction to Vue.js
AngularJS: an introduction
Practical AngularJS
Ad

Viewers also liked (8)

PPTX
Services Factory Provider Value Constant - AngularJS
PPTX
Single page application 04
PDF
AngularJS best-practices
PDF
AngularJS application architecture
PPTX
AngularJS Architecture
PDF
AngularJS - What is it & Why is it awesome ? (with demos)
PDF
AngularJS Basics with Example
PDF
AngularJS 101 - Everything you need to know to get started
Services Factory Provider Value Constant - AngularJS
Single page application 04
AngularJS best-practices
AngularJS application architecture
AngularJS Architecture
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS Basics with Example
AngularJS 101 - Everything you need to know to get started
Ad

More from LearningTech (20)

PPTX
PPTX
PostCss
PPTX
ReactJs
PPTX
Docker
PPTX
Semantic ui
PPTX
node.js errors
PPTX
Process control nodejs
PPTX
Expression tree
PPTX
SQL 效能調校
PPTX
flexbox report
PPTX
Vic weekly learning_20160504
PPTX
Reflection &amp; activator
PPTX
Peggy markdown
PPTX
Node child process
PPTX
20160415ken.lee
PPTX
Peggy elasticsearch應用
PPTX
Expression tree
PPTX
Vic weekly learning_20160325
PPTX
D3js learning tips
PPTX
git command
PostCss
ReactJs
Docker
Semantic ui
node.js errors
Process control nodejs
Expression tree
SQL 效能調校
flexbox report
Vic weekly learning_20160504
Reflection &amp; activator
Peggy markdown
Node child process
20160415ken.lee
Peggy elasticsearch應用
Expression tree
Vic weekly learning_20160325
D3js learning tips
git command

Recently uploaded (20)

PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
August Patch Tuesday
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
1. Introduction to Computer Programming.pptx
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
A comparative study of natural language inference in Swahili using monolingua...
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Univ-Connecticut-ChatGPT-Presentaion.pdf
August Patch Tuesday
Getting Started with Data Integration: FME Form 101
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
DP Operators-handbook-extract for the Mautical Institute
A novel scalable deep ensemble learning framework for big data classification...
cloud_computing_Infrastucture_as_cloud_p
Digital-Transformation-Roadmap-for-Companies.pptx
Tartificialntelligence_presentation.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
NewMind AI Weekly Chronicles - August'25-Week II
A comparative analysis of optical character recognition models for extracting...
1. Introduction to Computer Programming.pptx

Angular module

  • 3. Install  In the html <script src="angular.js"> <script src="angular-animate.js">  Download this file from  Google CDN - //ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-animate.js  Bower - bower install angular-animate.js @X.Y.Z  code.angularjs.org - //code.angularjs.org/X.Y.Z/angular-animate.js
  • 4. ngAnimate  The ngAnimate module provides support for CSS-based animations (keyframes and transitions) as well as JavaScript-based animations via callback hooks. Animations are not enabled by default, however, by including ngAnimate then the animation hooks are enabled for an Angular app.  var myModule = angular.module('myModule', ['ngAnimate']);
  • 5. ngAnimate by Css  ng-enter class 主要用於新添加的並渲染到頁面中.  ng-move class 主要用於當元素被移動時.  ng-leave class主要用於被刪除時.  starting class表示一個將要開始的動畫  active class 表示一個將要結束的動畫 /* The starting CSS styles for the enter animation */ .fade.ng-enter { transition:0.5s linear all; opacity:0; } /* The finishing CSS styles for the enter animation */ .fade.ng-enter.ng-enter-active { opacity:1; } <div ng-if="bool" class="fade"> Fade me in out </div> <button ng-click="bool=true">Fade In!</button> <button ng-click="bool=false">Fade Out!</button>
  • 6. ngAnimate by JavaScript  By making use of the module.animation() module function we can register the ainmation. <div ng-repeat="item in items" class="slide"> {{ item }} </div> myModule.animation('.slide', [function() { return { // make note that other events (like addClass/removeClass) have different function input parameters enter: function(element, doneFn) { jQuery(element).fadeIn(1000, doneFn); // remember to call doneFn so that angular knows that the animation has concluded }, move: function(element, doneFn) { jQuery(element).fadeIn(1000, doneFn); }, leave: function(element, doneFn) { jQuery(element).fadeOut(1000, doneFn); } } }]
  • 7. ngAria  The ngAria module provides support for common ARIA attributes that convey state or semantic information about the application for users of assistive technologies, such as screen readers.  ngAria – 幫助製作 AngularJS 自定義組件的新模塊
  • 8. ngAria - example  The disabled attribute is only valid for certain elements such as button, input and textarea. To properly disable custom element directives such as <md-checkbox> or <taco-tab>, using ngAria with ngDisabled will also add aria-disabled. This tells assistive technologies when a non-native input is disabled, helping custom controls to be more accessible. <md-checkbox ng-disabled="disabled"> <md-checkbox disabled aria-disabled="true">
  • 9. ngCookies  The ngCookies module provides a convenient wrapper for reading and writing browser cookies.  angular.module('app', ['ngCookies']);  Module Components  Service  $cookieStore: Objects put or retrieved from this storage are automatically serialized or deserialized by angular's toJson/fromJson.  $cookies: Provides read/write access to browser's cookies.  Provider  $cookiesProvider: Change the default behavior of the $cookies service.
  • 10. ngCookies - example angular.module('cookieStoreExample', ['ngCookies']) .controller('ExampleController', ['$cookieStore', function($cookieStore) { // Put cookie $cookieStore.put('myFavorite','oatmeal'); // Get cookie var favoriteCookie = $cookieStore.get('myFavorite'); // Removing a cookie $cookieStore.remove('myFavorite'); }]);
  • 11. ngMessages  The ngMessages module provides enhanced support for displaying messages within templates  Instead of relying on JavaScript code and/or complex ng-if statements within your form template to show and hide error messages specific to the state of an input field, the ngMessages and ngMessage directives are designed to handle the complexity
  • 12. ngMessages - example <form name="yourForm"> <label for="yourField">名稱1</label> <input id="yourField" type="text" ng-model="field1" name="yourField" required minlength="3" /> <div ng-if="yourForm.yourField.$error"> <!-- 需指定完整的 model --> <div ng-if=“yourForm.yourField.$error.required”>名稱是必填</div> <div ng-if="yourForm.yourField.$error.minlength">長度需要大於3</div> </div> </form> <form name="myForm"> <label for="myField">名稱</label> <input id="myField" type="text" ng-model="field2" name="myField" required minlength="3" /> <div ng-messages="myForm.myField.$error"> <!-- 包在 ng-messages 裡 myForm.myField.$error 的 children --> <div ng-message=“required”>名稱是必填</div> <div ng-message="minlength">長度需要大於3</div> </div> </form>
  • 13. ngSanitize  The ngSanitize module provides functionality to sanitize(清理) HTML. angular.module('sanitizeExample', ['ngSanitize']) .controller('ExampleController', ['$scope', '$sce', function($scope, $sce) { $scope.snippet = '<p style="color:blue">an htmln' + '<em onmouseover="this.textContent='PWN3D!'">click here</em>n' + 'snippet</p>'; $scope.deliberatelyTrustDangerousSnippet = function() { return $sce.trustAsHtml($scope.snippet); }; }]);
  • 14. ngTouch  The ngTouch module provides touch events and other helpers for touch- enabled devices.  ngClick  A more powerful replacement for the default ngClick designed to be used on touchscreen devices. Most mobile browsers wait about 300ms after a tap-and- release before sending the click event.  ngSwipeLeft, ngSwipeRight  Specify custom behavior when an element is swiped to the left(right) on a touchscreen device.
  • 15. ngTouch - ngSwipeLeft, ngSwipeRight  Ex. http://plnkr.co/edit/?p=preview <div ng-show="!showActions" ng-swipe-left="showActions = true"> Some list content, like an email in the inbox </div> <div ng-show="showActions" ng-swipe-right="showActions = false"> <button ng-click="reply()">Reply</button> <button ng-click="delete()">Delete</button> </div>

Editor's Notes

  • #8: http://ithelp.ithome.com.tw/question/10161588