Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
一些 Angular 的最佳实践
Search
Bin Xin
July 01, 2015
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
一些 Angular 的最佳实践
Bin Xin
July 01, 2015
Transcript
23 slides
ӞԶ Angular ጱ๋֯ਫ ᪢ 2015.7 1
ֵአ ControllerAs դ๊ $scope <script> angular.module('app', []) .controller('FooCtrl', function ()
{ this.foo = 'this is foo' }) </script> <div ng-app="app" ng-controller="FooCtrl as ctrl"> {{ ctrl.foo }} </div> 2015.7 2
$scope.ctrl = new Ctrl see 2015.7 3
Pros • ӧᵱᥝׁᩢ $scope ဳف • හഝᬰᛔݷҁݷᑮᳵ҂҅عݒᰁ٫ᑱ • ݢզعӞԶଉᥠጱᔩᔊҁైአ$scope.$watch҂ •
ฃၥᦶ • ᶎݻ๚ҁAngular2҂ 2015.7 4
ࣁ Directive Ӥֵአ module.directive('fooBar', function () { return { scope:
{}, template: '{{ ctrl.foo }}', controllerAs: 'ctrl', controller: function () { this.foo = 'this is foobar directive' } } }) 2015.7 5
Directive ጱᳯ᷌ module.directive('fooBar', function () { return { scope: {
data: '=' }, template: '{{ ctrl.foo }} {{ ctrl.data.xx }}', controllerAs: 'ctrl', controller: function ($scope) { this.foo = 'this is foobar directive' // handle data var self = this $scope.$watch('data', function (data) { self.data = data }) } } }) 2015.7 6
bindToController!! 2015.7 7
ֵአ Directive ᕟᕢᶭᶎ 2015.7 8
2015.7 9
Pros • ᕟկ۸ • ᶎݻ๚ҁAngular2҂ 2015.7 10
عֵአ $scope ᱾ᬰᤈᕟկԏᳵጱԻ ᭗ᬦֵአ Serviceҁහഝ҂ ᘏ eventsҁ᭗ᦔ҂ 2015.7 11
$scope.$broadcast('addTask', list) $scope.$emit('createdTask', task) see 2015.7 12
Pros • ܔݻහഝၞ • flux • ӧᵱᥝփ handler҅$scope Ԟๅےଗٳ •
<foo on-save="ctrl.create(foo)"/> 2015.7 13
Router ng-click="router.forward('/folder')" 2015.7 14
href="/folder" see 2015.7 15
Pros • ݢᦢᳯ • ຽٵ۸ 2015.7 16
ཛྷࣘဳف // directives/foo.js return function ($scope, $timeout) { return {
scope: {} template: 'xxx' link: function () {} } } // module.js module.directive('foo', ['$scope', '$timeout', foo]) 2015.7 17
// directives/foo.js return ['$scope', '$timeout', function ($scope, $timeout) { return
{ scope: {} template: 'xxx' link: function () {} } }] // module.js module.directive('foo', foo) 2015.7 18
// directives/foo.js module.directive('foo', ['$scope', '$timeout', function ($scope, $timeout) { return
{ scope: {} template: 'xxx' link: function () {} } }]) 2015.7 19
Extra: token vs cookie 2015.7 20
2015.7 21
Pros • CORS • Stateless • ຽٵ۸ https://tools.ietf.org/html/rfc7519 • قᒒঅ
• ฃၥᦶ see 2015.7 22
Thanks • http://www.benlesh.com/2013/10/title.html • http://blog.thoughtram.io/angularjs/2015/01/02/exploring- angular-1.3-bindToController.html • http://jwt.io • https://auth0.com/blog/2014/01/07/angularjs-
authentication-with-cookies-vs-token/ 2015.7 23
Other Decks in Programming
See All in Programming
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
190
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
340
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
210
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.9k
Будущее локальных LLM – Алексей Голобурдин, PythoNN
sobolevn
0
120
Web Framework Benchmark Battle 2026, Any%
a_matsuda
3
3.2k
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
16
9.1k
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
240
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
160
Next.js: The final boss of Web Performance
guaca
0
410
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
110
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
860
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Rails Girls Zürich Keynote
gr2m
96
14k
Building Adaptive Systems
keathley
44
3.3k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
The SEO identity crisis: Don't let AI make you average
varn
0
630
How to build a perfect <img>
jonoalderson
1
6.2k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Documentation Writing (for coders)
carmenintech
77
5.6k
Are puppies a ranking factor?
jonoalderson
2
4.2k
Designing Experiences People Love
moore
143
24k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Paper Plane
katiecoart
PRO
6
55k