angularjs: q&a

48
AngularJS: Q&A

Upload: piotr-kowalski

Post on 14-Apr-2017

850 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: AngularJS: Q&A

AngularJS: Q&A

Page 2: AngularJS: Q&A

Who am I?

Kierownik Działu Aplikacji Webowych

Cyfrowy Polsat, Warsaw

JavaScript Ninja. Mac lover. Pebble evangelist.

Organizator WarsawJS

"Kto chce szuka sposobu, kto nie chce szuka powodu."

Piotr Kowalski

2

Page 3: AngularJS: Q&A

JavaScript Ninja

Page 4: AngularJS: Q&A

piecioshka.pl/blog github.com/piecioshka

twitter.com/piecioshka soundcloud.com/piecioshka

Where am I?

Page 5: AngularJS: Q&A

Book: AngularJS

Page 6: AngularJS: Q&A

Book: AngularJS. Pierwsze Kroki.

Page 7: AngularJS: Q&A

My privatenotes... let's go!

Page 8: AngularJS: Q&A
Page 9: AngularJS: Q&A
Page 10: AngularJS: Q&A

Law of Demeter

•   Object itself

•   Method 's parameters

•  Any objects created/instantiated within m

•   Object 's direct component objects

•  A global variable, accessible by Object , in the scope of method

Reference: https://en.wikipedia.org/wiki/Law_of_Demeter

10

Page 11: AngularJS: Q&A
Page 12: AngularJS: Q&A

Demo

I was created special project for test that:

•   https://github.com/piecioshka/test-angular-update-model-and-view

12

Page 13: AngularJS: Q&A
Page 14: AngularJS: Q&A

Demo

I was created special project for test that:

•   https://github.com/piecioshka/test-angular-directive-execution-order

14

Page 15: AngularJS: Q&A
Page 16: AngularJS: Q&A

Demo

I was created special project for test that:

•   https://github.com/piecioshka/test-angular-un-register-watch

16

Page 17: AngularJS: Q&A
Page 18: AngularJS: Q&A
Page 19: AngularJS: Q&A

More? Go go go!

Page 20: AngularJS: Q&A
Page 21: AngularJS: Q&A
Page 22: AngularJS: Q&A

Code Samples

$scope.title = 'Function';

// Mozilla Firefox support Arrow Function natively.

setTimeout( () => {

$scope.title = 'Arrow Function?';

}, 1000);

01.

02.

03.

04.

05.

06.

22

Page 23: AngularJS: Q&A
Page 24: AngularJS: Q&A

Code Samples

// Controller

$scope.dataStructure = { foo: 'bar' } ;

// View

<span ng-bind="dataStructure"></span>

{{ dataStructure }}

{{ dataStructure | json }}

01.

02.

03.

04.

05.

06.

07.

24

Page 25: AngularJS: Q&A

Code Samples: Results

// View (compiled)

[object Object]

{"foo":"bar"}

{ "foo": "bar" }

01.

02.

03.

04.

25

Page 26: AngularJS: Q&A
Page 27: AngularJS: Q&A

Code Samples: Use other controller

mod.controller('HelperController', function ($scope) {

$scope.helper = 1;

});

mod.controller('DependencyController', function ($scope, $controller) {

var $newScope = $scope.$new();

$controller('HelperController', {

$scope: $newScope

});

console.log($newScope.helper); // 1

});

01.

02.

03.

04.

05.

06.

07.

08.

09.

10. 27

Page 28: AngularJS: Q&A
Page 29: AngularJS: Q&A
Page 30: AngularJS: Q&A
Page 31: AngularJS: Q&A
Page 32: AngularJS: Q&A

Code Samples

<!-- interpolation -->

<span ng-cloak >{{ title }}</span>

<!-- directive ng-bind -->

<span ng-bind="title"></span>

01.

02.

03.

04.

05.

32

Page 33: AngularJS: Q&A
Page 34: AngularJS: Q&A

Code Samples

< ng-switch on="foo" >

<span ng-switch-when="bar">Bar</span>

<span ng-switch-when="baz" >Baz</span>

<span ng-switch-when="abc">Abc</span>

<span ng-switch-default >...</span>

</ng-switch>

01.

02.

03.

04.

05.

06.

34

Page 35: AngularJS: Q&A
Page 36: AngularJS: Q&A

Code Samples

<body ng-init=" cut = false ;">

<div ng-cut="cut = true" >

Lorem ipsum...

</div>

Cut? {{ cut }}

</body>

01.

02.

03.

04.

05.

06.

36

Page 37: AngularJS: Q&A
Page 38: AngularJS: Q&A
Page 39: AngularJS: Q&A

Demo

I was created special project for test that:

•   https://github.com/piecioshka/test-angular-disable-watchers

39

Page 40: AngularJS: Q&A
Page 41: AngularJS: Q&A
Page 42: AngularJS: Q&A
Page 43: AngularJS: Q&A
Page 44: AngularJS: Q&A
Page 45: AngularJS: Q&A

Last but not least!

Page 46: AngularJS: Q&A
Page 47: AngularJS: Q&A

Thanks!

Page 48: AngularJS: Q&A

Links

Slides

https://github.com/piecioshka/presentation-angularjs-q-and-a

Post about AngularJS training:

http://piecioshka.pl/blog/2015/06/27/szkolenie-angularjs-podstawy-

relacja-live.html

My private projects for testing AngularJS (7):

https://github.com/search?q=user:piecioshka+angular

48