This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controller): support as instance syntax
Support ng-controller="MyController as my" syntax which publishes the controller instance to the current scope. Also supports exporting a controller defined with route: ````javascript angular.module('routes', [], function($routeProvider) { $routeProvider.when('/home', {controller: 'Ctrl as home', templateUrl: '...'}); }); ````
- Loading branch information
Showing
7 changed files
with
181 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd38cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to find somewhere desription/discussion about this commit? Is using
this.smth = ...
more prefarable then$scope.smth = ...
? If yes, why? I assume nothing is added just to add, so there should be a good reason :) thnx.cd38cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about directive controllers?
cd38cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, now to test most controllers you won't have to create a mock scope and as well not inject scope into the controller.
When your using inherited properties from up the scope chain it's more explicit.
Can't wait to use this. but would like to know about directive controllers.
Though, I assume you can use the
ng-controller
directive in the directive template if it can't be done in the object definitioncd38cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directive controllers would be terrific for publishing an API for more behavior or dynamic directives like dialogs and popovers.
cd38cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olostan, maybe if you wanted to make whatever you are doing in your controller private? Because $scope inherits from it's parent and makes properties and methods available for it's children as well. If you put the properties and methods directly in the controller instead, they will remain private to that controller.
cd38cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olostan, just found this video by John Lindquist that better explains why you would want to use it - http://www.egghead.io/video/tTihyXaz4Bo
I do hope they keep the feature as it seems very very useful!
cd38cbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to inject the alias in the controller?
Or even better inject a child scope "scoped" to the controller ($controllerScope),
so you can $watch something in the controller without knowing the alias ($watch("member" where member belong to controller).
Another idea: provide a way to make the controller inherit Scope (or mix it in) - not sure this one is a good idea