Hi,
When you create a service that have global properties, like:
import {Injectable} from "angular2/core";
@Injectable()
export class MyService {
private myValue;
constructor() {}
setValue(val) {
this.myValue = val;
}
getValue(val) {
return this.val;
}
}
And you need access it globally from your app initialising:
import {MyService} from './services/my.service';
bootstrap(App, [MyService, COMMON_DIRECTIVES, ROUTER_DIRECTIVES,
ROUTER_PROVIDERS, HTTP_PROVIDERS]); // directives added here are available
to all children
And you need access it from your component:
import {MyService} from '../services/my.service';
@Component({
selector: 'some-component',
template: `
<div>MyValue: {{val}}</div>
`
})
export class SomeComponent {
constructor(private myService:MyService) {
}
get val() {
return this.myService.getValue();
}
}
You always create a constructor with private variable creation as the
custom service. No problem here.
My question is about the possibility of create the component, with the
services injected, but without a constructor and private param.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.