Comments (4)
- According to the AngularJS documentation, there is a component called "service", which could be defined using
.factory
,.service
or.provider
. The services section summarize all ways of creating services. You're right that there might be misunderstanding so I'm going to include additional information, in order to clarify it. - The services defined with
.service
are instantiated through$injector.instantiate
invoking the constructor function with thenew
operator (just like you said). Naming services created with.factory
and ones created with.service
in different way is definitely inconsistent. My suggestion is to use UpperCamelCase for services, which define constructor function, which later when the service have been injected, could be invoked withnew
, i.e.:
module.controller('MainCtrl', function ($scope, User) {
$scope.user = new User('foo', 42);
});
module.factory('User', function () {
return function User(name, age) {
this.name = name;
this.age = age;
};
});
- Klassical is intentional misspelling. Since in JavaScript we don't have classes and the "classical" OOP impossible some authors (like Stoyan Stefanov in his "JavaScript Patterns"), intentionally misspell classes with "k", I'm just following them.
from angularjs-style-guide.
@hansifer I did some additional changes in the "Services" section. Please, take a look and tell me whether you find it more clear and correct in order to close the issue.
from angularjs-style-guide.
Thanks for the quick reply and clarifications. I'm still relatively new to Angular and your explanations offer new insight.
The updates look good, thanks.
from angularjs-style-guide.
Thats absolutely find, everyone begins from somewhere.
Thank you a lot for the suggestions!
from angularjs-style-guide.
Related Issues (20)
- Add recommendation for using 'controller as' syntax HOT 3
- User Services as your MVC 'Model' HOT 4
- Feature - add a 'Tests' section HOT 1
- Add benchmarks section
- Migration to Angular 2.0 HOT 6
- Add license HOT 2
- Angular Directory Structure - Addition of Modules HOT 1
- Naming services HOT 1
- Issue: Controller example does not follow styleguide
- Feature: Add guidelines for Constants
- Feature: Add guidelines for Components
- Feature: Request for guidelines on views
- there may be a mispell HOT 2
- Style guide plugin HOT 1
- Conflicts with Google best practices doc? HOT 1
- Please clarify the wording HOT 2
- Recommendations for module constant usage? HOT 3
- How to avoid “polluting” the resolve method with ui-router HOT 1
- Naming conventions for directories with multiple words
- Always including templates / partials along-side other code? HOT 1
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 angularjs-style-guide.