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
85
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
91
bootstrap single page apps
damienklinnert
1
310
test your nodejs code
damienklinnert
5
360
Other Decks in Programming
See All in Programming
SourceGeneratorのススメ
htkym
0
200
並行開発のためのコードレビュー
miyukiw
1
1.3k
Package Management Learnings from Homebrew
mikemcquaid
0
230
CSC307 Lecture 10
javiergs
PRO
1
670
CSC307 Lecture 06
javiergs
PRO
0
690
Gemini for developers
meteatamel
0
110
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.6k
dchart: charts from deck markup
ajstarks
3
1k
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
150
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
620
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
210
Featured
See All Featured
Balancing Empowerment & Direction
lara
5
900
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
180
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Designing Experiences People Love
moore
144
24k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
67
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
430
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
260
Building Applications with DynamoDB
mza
96
6.9k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
97
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