Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Difference between Angular.service and Angular.factory

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4
    Comment on it

    Services

    Syntax:
    module.service( 'serviceName', function );

    Result: When declaring serviceName as an injectable argument you will be provided with the instance of a function passed to module.service.
    Usage: Could be useful for sharing utility functions that are useful to invoke by simply appending () to the injected function reference. Could also be run with injectedArg.call( this ) or similar.

    When you're using Service, Angular instantiates it behind the scenes with the 'new' keyword. Because of that, you'll add properties to 'this' and the service will return 'this'. When you pass the service into your controller, those properties on 'this' will now be available on that controller through your service.

    Factories

    Syntax:
     module.factory( 'factoryName', function );

    Result: When declaring factoryName as an injectable argument you will be provided with the value that is returned by invoking the function reference passed to module.factory.
    Usage: Could be useful for returning a 'class' function that can then be new'ed to create instances.

    When you're using a Factory you create an object, add properties to it, then return that same object. When you pass this factory into your controller, those properties on the object will now be available in that controller through your factory.
    angular angular service factory AngularJS Services in AngularJS html css script

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: