Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Two instances of the same service #495

@alescdb

Description

@alescdb

When a service is use on the same "page" by two components, we have two differents instances of the same service, this does not seems to be a normal behaviour.
In Angular 2 (ts), I do not have the same behaviour.

Note that I've tried adding the class to bootstrap() but it does not make a difference.

Example :

If we take the stater project of IntelliJ (I think it's https://github.com/google/stagehand)
and change AppComponent to this :

@Component(
  selector: 'my-app',
  styleUrls: const ['app_component.css'],
  templateUrl: 'app_component.html',
  directives: const [materialDirectives, TodoListComponent],
  providers: const [materialProviders, TodoListService],
)
class AppComponent implements OnInit {
  TodoListService todoListService;

  AppComponent(this.todoListService);

  @override
  ngOnInit() {
    print("AppComponent::ngOnInit() : " + this.todoListService.hashCode.toString());
  }
}

And change the ngOnInit() in TodoListComponent to this :

Future<Null> ngOnInit() async {
  print("TodoListComponent::ngOnInit() : " + this.todoListService.hashCode.toString());
  items = await todoListService.getTodoList();
}

The output will look like this :

Observatory listening at http://127.0.0.1:60762/
 AppComponent::ngOnInit() : 683014649
 TodoListComponent::ngOnInit() : 655556724

Using Dart : 1.24.2

pubspec.yaml

name: test
description: A web app that uses AngularDart Components
version: 0.0.1
#homepage: https://www.example.com
#author: adb <email@example.com>

environment:
  sdk: '>=1.23.0 <2.0.0'

dependencies:
  angular2: ^3.0.0
  angular_components: ^0.5.1

dev_dependencies:
  angular_test: ^1.0.0-beta+2
  browser: ^0.10.0
  dart_to_js_script_rewriter: ^1.0.1
  test: ^0.12.0

transformers:
- angular2:
    entry_points: web/main.dart
- angular2/transform/reflection_remover:
    $include: test/**_test.dart
- test/pub_serve:
    $include: test/**_test.dart
- dart_to_js_script_rewriter

# Uncomment the following in sdk 1.24+ to make pub serve
# use dartdevc (webdev.dartlang.org/tools/dartdevc).
#web:
#  compiler:
#    debug: dartdevc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions