Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit e67c72a

Browse files
committed
Update TIPS-AND-TRICKS.md
1 parent 64853b4 commit e67c72a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

TIPS-AND-TRICKS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,8 @@ If you look at [ui-select](https://github.com/angular-ui/ui-select) i love `cont
7979
and that really is what it’s doing. It’s the controls for my `ui-select` widget.
8080
`personCtrl.person.open()` just doesn’t make sense if you read it. The ‘controller’ (guy doing shit to people) isn’t the one with the method, the object itself has methods that work upon itself.
8181
Doing `personCtrl.open()` is just a sign of bad design, because controllers should be skinny.
82+
83+
#### Never use scope inheritence across controllers (ui-views)
84+
This is like using `$rootScope`, it's equivalent to using global variables and relies upon assumptions that variables will exist. It makes controllers (and views) depend on variables that may or may not exist, and makes it difficult for developers to see where these variables came from. If you wish to use a service, resolve or something inside of a route controller or view, you should **always re-inject the dependency and place it on the scope redundantly**. This is single-handedly the key to ensuring that your codebase has a solid contract and that the quality of your code stands up to refactoring. Even if it means placing the same objects onto the same variables in the same place on the scope, do it. Period.
85+
86+
The only time scope inheritence is good is when working with directives. Directives are view-centric data that do nothing more than decorate the scope based on what came before or what comes after, and even this is quickly being deprecated in favor of explicit attributes and highly reusable directives.

0 commit comments

Comments
 (0)