22
AngularJS Training - Day #5 By George

AngularJS Training Day4

Embed Size (px)

DESCRIPTION

tr

Citation preview

Page 1: AngularJS Training Day4

AngularJS Training - Day #5

By

George

Page 2: AngularJS Training Day4

Agenda• $scope Hierarchy• AngularJS $watch() , $observe, $digest() and $apply()• AngularJS Events

– ng-click– ng-dbl-click– ng-mousedown– ng-mouseup– ng-mouseenter– ng-mouseleave– ng-mousemove– ng-mouseover– ng-keydown– ng-keyup– ng-keypress– ng-change

Page 3: AngularJS Training Day4

scope Hierarchy

• The $scope object used by views in AngularJS are organized into a

hierarchy

• There is a root scope, and the root scope has one or more child scopes

• Each view has its own $scope (which is a child of the root scope),

• so whatever variables one view controller sets on its $scope variable, those

variables are invisible to other controllers.

Page 4: AngularJS Training Day4

scope Hierarchy

Page 5: AngularJS Training Day4

AngularJS $watch() , $digest() and $apply()

• A watch means that AngularJS watches changes in the variable on the $scope object.

• $scope.$digest() function iterates through all watches and checks if any of the watched variables have changed

• The $scope.$apply() function is used to execute some code, and then call $scope.$digest() after that, so all watches are checked and the corresponding watch listener functions are called.

• The $apply() function is useful when integrating AngularJS with other code.

Page 6: AngularJS Training Day4

$watch() & $watchCollection

• Syntax: • $watch(watchExpression, listener, [objectEquality]);

• watchCollection() function was added for collection-oriented change management.

Page 7: AngularJS Training Day4

$watch using function call

Page 8: AngularJS Training Day4

$observe

• Observes an interpolated attribute.

• The observer is then invoked whenever the interpolated value changes

• Syntax:– $observe(key, fn);

Page 9: AngularJS Training Day4

$digest() & $apply()

• The $scope.$digest() function iterates through all the watches in the $scope object

• The $scope.$apply() function takes a function as parameter which is executed, and after that $scope.$digest() is called internally.

Page 10: AngularJS Training Day4

ng-click Directive

• The ngClick directive allows you to specify custom behavior when an element is clicked.

Page 11: AngularJS Training Day4

ng-dbl-click

• The ngDblclick directive allows you to specify custom behavior on a dblclick event.

Page 12: AngularJS Training Day4

ngMousedown

• The ngMousedown directive allows you to specify custom behavior on mousedown event.

Page 13: AngularJS Training Day4

ngMouseup

• Specify custom behavior on mouseup event.

Page 14: AngularJS Training Day4

ngMouseenter

• Specify custom behavior on mouseenter event.

Page 15: AngularJS Training Day4

ngMouseleave

• Specify custom behavior on mouseleave event.

Page 16: AngularJS Training Day4

ngMousemove

• Specify custom behavior on mousemove event.

Page 17: AngularJS Training Day4

ngMouseover

• Specify custom behavior on mouseover event.

Page 18: AngularJS Training Day4

ngKeydown

• Specify custom behavior on keydown event.

Page 19: AngularJS Training Day4

ngKeyup

• Specify custom behavior on keyup event.

Page 20: AngularJS Training Day4

ngKeypress

• Specify custom behavior on keypress event.

Page 21: AngularJS Training Day4

ngChange• Evaluate the given expression when the user changes the input.• The ngChange expression is only evaluated when a change in the input value

causes a new value to be committed to the model.• It will not be evaluated: if the model is changed programmatically and not by a

change to the input value• Note, this directive requires ngModel to be present.

Page 22: AngularJS Training Day4

Assignments