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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
damienklinnert
April 09, 2014
Programming
92
1
Share
angular decorate
Use AngularJS' decorate function with ease
damienklinnert
April 09, 2014
More Decks by damienklinnert
See All by damienklinnert
Angular Performance Tuning
damienklinnert
4
280
Angular Performance Talk
damienklinnert
0
130
Fight the Rot - Refactor stinky JavaScript
damienklinnert
0
190
modern web apps
damienklinnert
0
120
Become a node package maintainer
damienklinnert
1
96
bootstrap single page apps
damienklinnert
1
310
test your nodejs code
damienklinnert
5
360
Other Decks in Programming
See All in Programming
AI開発を加速するためにテスト戦略を言語化した
yoshihiro_shu
0
100
iOS26時代の新規アプリ開発
yuukiw00w
0
230
新規プロダクトを高速で生み出すハーネスエンジニアリング
seanchas116
19
7.7k
OSもどきOS
arkw
0
370
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
440
Inspired By RubyKaigi (EN)
atzzcokek
0
470
ECR拡張スキャンでSBOMを収集して サプライチェーン攻撃の影響調査を 爆速で終わらせてみた
akihisaikeda
2
210
[KCD Czech] eBPF Meets the GPU: Future of AI Infra Observability
doniacld
0
130
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
290
AIエージェントの隔離技術の徹底比較
kawayu
0
450
Oxlintはいかにしてtsgolintのlint ruleを呼び出しているのか
syumai
2
1k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.2k
Featured
See All Featured
Leo the Paperboy
mayatellez
7
1.8k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
190
Deep Space Network (abreviated)
tonyrice
0
160
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
370
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
270
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
370
New Earth Scene 8
popppiees
3
2.3k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
190
A Soul's Torment
seathinner
6
2.9k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Code Reviewing Like a Champion
maltzj
528
40k
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