Comments (7)
@amiceli A nice alternative is ng-annotate which eliminates the need for lengthy $inject arrays:
/* @ngInject */
function MainController($scope, $q, Api, segments, ResourceService, AdminService, SweetAlertService, UsersCsvService, UsersSearchService, CriteriaService, $rootScope) {
// code here
}
from angular-styleguide.
Read this discussion. IMHO, $watch
should be avoided as possible. Use ngChange
instead.
from angular-styleguide.
First, $scope
, $rootScope
and $q
have nothing to do in your controller.
I use a max size line of 120 chars in my source code.
If the controller declaration goes away 120 chars, i fold line before the limit then i fold the $inject
line regarding where i have folded the controller declaration.
Example :
MainController.$inject = [
'Api', 'segments', 'ResourceService', 'AdminService','SweetAlertService', 'UsersCsvService',
'UsersSearchService', 'CriteriaService'
];
function MainController(Api, segments, ResourceService, AdminService, SweetAlertService, UsersCsvService,
UsersSearchService, CriteriaService) {
// code here
}
In this example with a 120 chars line, i could have this :
MainController.$inject = [
'Api', 'segments', 'ResourceService', 'AdminService','SweetAlertService', 'UsersCsvService', 'UsersSearchService',
'CriteriaService'
];
function MainController(Api, segments, ResourceService, AdminService, SweetAlertService, UsersCsvService,
UsersSearchService, CriteriaService) {
// code here
}
But to keep consistency between $inject
and controller declaration i fold line in $inject
where i fold line in controller declaration.
I am not sure your arguments
use is working with AngularJs injection system and minification.
from angular-styleguide.
Thanks for your answer.
120 chars limit is a good solution, I adopt it !
Why $rootScope
and $scope
should not be in my controller ?
How do you sent events without $on
and $broadcast
?
from angular-styleguide.
For $rootScope
and $scope
you should read Y031.
IMHO there is no reason to inject them except when a third party library that you must use needs them to communicate with events. You have to keep in mind that scopes does not exist anymore in Angular. So if you want to handle your technical debt you need to keep consistency in your projects between AngularJS and Angular to allow a future migration when AngularJS will become deprecated.
For events, you should read this discussion.
from angular-styleguide.
Ok, I note it.
Thanks.
from angular-styleguide.
@bampakoa thanks
@MarcLoupias An another question, without $scope
, how to watch a property change event ? Like $watch
from angular-styleguide.
Related Issues (20)
- Y022 - Naming Conventions For Functions Inside IIFE HOT 1
- JS Hint configuration code is out of date.
- Can you give simple Hello World Program? HOT 2
- dataService calls when inside page controllers vs component/directive controllers. HOT 2
- Best way for required directive attribute HOT 2
- NetBeans templates, redux? HOT 1
- Best Practices for `templateUrl` and `ngInclude` URLs HOT 3
- Arrays under scope.vm of directive undefined HOT 7
- Proposal: change from "do" to "consider" adding 'Service' suffix to Service (02-04) classes because it doesn't improve clarity or add value HOT 7
- Where is the best location to place HttpInterceptors?
- Why styleguide suggest use class instead of interface? HOT 3
- A1 - How to pass object received with $routeProvider to other route HOT 1
- Style 03-05 missing! HOT 1
- Angular 5 style guide? HOT 1
- Confusing Information on SharedModule and CoreModule HOT 3
- Should "public" always be omitted in TypeScript? HOT 1
- Private variable - leading underscore HOT 7
- Jasmine Test case failing HOT 1
- AngularJS-UnitTesting | Weather App | Karma
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-styleguide.