zoukankan      html  css  js  c++  java
  • Angularjs service vs factory vs provider

    Angular provides us with three ways to create and register our own service.

    1) Factory

    2) Service

    3) Provider

    TL;DR

    1) When you’re using a Factory you create an object, add properties to it, then return that same object. When you pass this service into your controller, those properties on the object will now be available in that controller through your factory.

    2) When you’re using Service, it’s instantiated 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.

    3) Providers are the only service you can pass into your .config() function. Use a provider when you want to provide module-wide configuration for your service object before making it available.

    NON TL;DR

    1) Factory

  • 相关阅读:
    Bootstrap 4 网格的基本结构
    Js 框架之Vue .JS学习记录 ① 与Vue 初识
    ASP.NET 发送邮件 SMTP
    c# 多线程简化
    ASP.NET Razor
    ASP.NET MVC 简单介绍①
    握手7
    握手6
    握手5
    握手4
  • 原文地址:https://www.cnblogs.com/yk00/p/5144430.html
Copyright © 2011-2022 走看看