Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习 AngularJS,我注意到 A Factory 是 Provider 的简写。你能告诉我应该/必须使用提供者而不是工厂的具体场景吗?如果使用工厂方法而不是提供者,代码的可读性会更高。
当提供者本身具有您希望服务的用户在应用程序的配置阶段调用的方法时,提供者是必需的。
参见例如$location服务:它有一个$locationProvider允许将其设置为 html5 模式,同时正在配置应用程序(使用module.config())。
$location
$locationProvider
module.config()