Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
angular decorate
Search
damienklinnert
April 09, 2014
Programming
1
88
angular decorate
Use AngularJS' decorate function with ease
damienklinnert
April 09, 2014
Tweet
Share
More Decks by damienklinnert
See All by damienklinnert
Angular Performance Tuning
damienklinnert
4
270
Angular Performance Talk
damienklinnert
0
130
Fight the Rot - Refactor stinky JavaScript
damienklinnert
0
180
modern web apps
damienklinnert
0
120
Become a node package maintainer
damienklinnert
1
92
bootstrap single page apps
damienklinnert
1
310
test your nodejs code
damienklinnert
5
360
Other Decks in Programming
See All in Programming
CSC307 Lecture 14
javiergs
PRO
0
450
LangChain4jとは一味違うLangChain4j-CDI
kazumura
1
150
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
220
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
130
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
580
エラーログのマスキングの仕組みづくりに役立ったASTの話
kumoichi
0
110
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.4k
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
TROCCOで実現するkintone+BigQueryによるオペレーション改善
ssxota
0
140
TipKitTips
ktcryomm
0
150
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
350
CSC307 Lecture 12
javiergs
PRO
0
460
Featured
See All Featured
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
74
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Visualization
eitanlees
150
17k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
My Coaching Mixtape
mlcsv
0
64
The Spectacular Lies of Maps
axbom
PRO
1
580
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
140
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Transcript
$PROVIDE .DECORATOR() MODIFYING THE BEHAVIOR OF ANGULARJS' CORE SERVICES
DAMIEN KLINNERT Software Engineer at Small-Improvements damienklinnert.com twitter.com/damienklinnert github.com/damienklinnert
THE DECORATOR PATTERN
None
THE COMPLEX WAY angular.module(moduleName, []) .config(function ($provide) { $provide.decorator(serviceName, function
($delegate) { // modify behavior here return $delegate; }); });
THE SIMPLE WAY angular.module(moduleName, []) .decorate(serviceName, function ($delegate) { //
modify behavior here return $delegate; }); www.github.com/damienklinnert/angular-decorate
ONE APPEND FILE EXTENSION IN $TEMPLATECACHE.GET()
What you have is: <div ng-include="'views/custom-template.html'"></div> What you want is:
<div ng-include="'views/custom-template'"></div>
// Decorator definition angular.module('$templateCache+get', ['ng']) .decorate('$templateCache', function ($delegate) { var
_get = $delegate.get; $delegate.get = function (key) { return _get.call(_get, key + ".html"); }; return $delegate; }); // Use decorator in whole app angular.module('app', ['$templateCache+get', ...])
TWO ADD BASEURL TO EACH $RESOURCE
Make this possible: var users = $resource('http://localhost/users'); console.log(users.baseUrl); // this
is new
// Decorator definition angular.module("$resource+baseUrl", ['ngResource']) .decorate('$resource', function ($delegate) { return
function (baseUrl) { var ret = $delegate.apply(this, arguments); ret.baseUrl = baseUrl; return ret; }; }); // Use decorator in whole app angular.module('app', ['$resource+baseUrl', ...])
THREE INSTRUMENT ANGULAR PERFORMANCE
What can you do with this? angular.module('$rootScope+instrument', []).decorate('$rootScope', function ($delegate)
{ $delegate.__proto__.$watch = function () { ... }; $delegate.__proto__.$apply = function () { ... }; return $delegate; });
THANK YOU RELATED MATERIAL angular-decorate www.github.com/damienklinnert/angular-decorate Hacking Core Directives in
AngularJS http://briantford.com/blog/angular-hacking-core.html Angular $provide http://docs.angularjs.org/api/auto/object/$provide