I was having trouble injecting a service into a component using ES5. I was finally able to get it to work, but discovered a couple different ways a service can be declared. Are one of these the more "Angular" way to declare a service?
Here is the component
(function (app) {
app.employeeSearchComponent = ng.core
.Component({
selector: 'employee-search',
templateUrl: rootUrl + 'Home/EmployeeSearch',
providers: [app.Service]
})
.Class({
constructor: [app.Service, function(service) {
console.log(service.greeting);
}]
});
})(window.app || (window.app = {}));
Here is the service (Option 1)
(function(app) {
app.Service = ng.core.Class({
constructor: function(){},
greeting: function() {
return 'hello';
}
});
})(window.app || (window.app = {}));
Here is the service (Option 2)
(function(app) {
app.Service = function() {
this.greeting = function() {
return 'hello';
}
};
})(window.app || (window.app = {}));