4

As Controller is deprecated, is there good replacement for it?

I understand, why it was deprecated, but now need to find a replacement for it.

Assuming that I need to publish some functions to HTML (so Decorators couldn't be used), but without any template HTML (so Component couldn't be used).

Moreover, if there is a state, that these functions could use.

Example:

<div>
  <div request-sender>First sender:<button ng-click="sender.send()">Send1</button></div>
  <div request-sender>And <button ng-click="sender.send()">Send2</button> - second sender</div>
</div>

Code:

@Controller(selector:'request-sender') 
class SenderCtrl {
   int counter = 0;
   Http _http;
   SenderCtrl(this._http);
   void send() { counter++;_http.get('someUrl/$counter'); }
}

So if I press two times on first button, then clicking to second button will issue request to someUrl/1 and not someUrl/3

Valentyn Shybanov
  • 19,331
  • 7
  • 66
  • 59
  • Did you check these questions http://stackoverflow.com/questions/23150818, http://stackoverflow.com/questions/23549800 – Günter Zöchbauer Jun 18 '14 at 14:28
  • possible duplicate of [Why is Controller deprecated in AngularDart 0.10.0?](http://stackoverflow.com/questions/23150818/why-is-controller-deprecated-in-angulardart-0-10-0) – Pixel Elephant Jun 18 '14 at 14:44
  • Sure I've checked all questions and issues on github, but didn't found good solution, except Component with template kind of `
    `, but it looks ugly and adds additional elements.
    – Valentyn Shybanov Jun 18 '14 at 14:48
  • I haven't seen any better answers yet but maybe someone else has a good idea. – Günter Zöchbauer Jun 18 '14 at 14:51
  • @GünterZöchbauer in these comments described reason (move context to strict typed objects instead of Map), but there is no solution, with which we can have same functionality. Did you found? – Valentyn Shybanov Jun 18 '14 at 14:53
  • 1
    I know, there is no (not yet a) good answer. But its not considered good practice on SO to ask a question again just because an existing question has not the desired answer. – Günter Zöchbauer Jun 18 '14 at 14:55
  • 1
    @ValentynShybanov You can follow the [GitHub issue](https://github.com/angular/angular.dart/issues/919) that Günter linked in his answer. Once that is closed, an answer should emerge in the next Angular version. – Pixel Elephant Jun 18 '14 at 14:59
  • @GünterZöchbauer There is a question "why controllers are deprecated" and it is answered. My question is to find a replacement for them with practical example, that couldn't be covered by any comment or link, provided in previous question. These questions are different - I DO fully understand WHY controllers are deprecated, and now searching answer for another question - HOW to achieve desired functionality without controllers. It is not asking same question. – Valentyn Shybanov Jun 18 '14 at 14:59
  • @PixelElephant after that issue would be closed, you would be able to provide a single context as root context of application. But in my example, you should have two contex. How single context would help? Also imagine, if sample HTML/Dart code is part of some library, and main application would have own root contex. In this case you couldn't even put sub-contexes as properties of root contex. So solving that issue won't solve described use-case. – Valentyn Shybanov Jun 18 '14 at 15:05

1 Answers1

1

You can have a look at this commit, the examples are changed to reflect the deprecation of the controller:

https://github.com/angular/angular.dart/commit/5f8e27659ffb0140e0c153f8cecd627df273bfd2

Patrick Cornelissen
  • 7,968
  • 6
  • 48
  • 70