Coder Social home page Coder Social logo

Comments (7)

bampakoa avatar bampakoa commented on June 10, 2024 2

@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.

MarcLoupias avatar MarcLoupias commented on June 10, 2024 2

Read this discussion. IMHO, $watch should be avoided as possible. Use ngChange instead.

from angular-styleguide.

MarcLoupias avatar MarcLoupias commented on June 10, 2024

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.

amiceli avatar amiceli commented on June 10, 2024

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.

MarcLoupias avatar MarcLoupias commented on June 10, 2024

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.

amiceli avatar amiceli commented on June 10, 2024

Ok, I note it.
Thanks.

from angular-styleguide.

amiceli avatar amiceli commented on June 10, 2024

@bampakoa thanks

@MarcLoupias An another question, without $scope, how to watch a property change event ? Like $watch

from angular-styleguide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.