Answer the question
In order to leave comments, you need to log in
Ang2 How to make Singleton Provider?
Hello. The project has:
main ( NgModule ) - module and bootstrap.
app ( AppComponent ) - the initial component.
inputdata( InputComponent ) - the component that displays the input field. provider is using.
service ( DataService ) - service provider.
The structure in general looks like this Page like this
HTML like this
<application>
<h2>App</h2><br>
<inputdata>
<input ng-reflect-model="12332" class="ng-valid ng-dirty ng-touched">
<input ng-reflect-value="12332">
<hr>
</inputdata>
<inputdata>
<input ng-reflect-model="123" class="ng-untouched ng-pristine ng-valid">
<input ng-reflect-value="123">
<hr>
</inputdata>
</application>
Answer the question
In order to leave comments, you need to log in
Specify a service in the component above (a component or ng module that contains both of your data inputs) and it will be a singleton. And then inject your service into the child components you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question