3
votes

I want to call a destroy function when the dart-angular controller are removed.

This is the angular.js solution.

$scope.$on("$destroy", function() {
       alert("destroy");
});

My try in Dart

class TestController...

TestController(Scope $scope){
    $scope.$on("$destroy",(){
            print("destroy");
    });
}

and this is the Error Code

Error!
NoSuchMethodError : method not found: 'destroy'

$destroy or destroy literal is not working. Any Idea?

2
Try using: $scope.$on(r'$destroy', () { (using r) - Florent
Yes that works as well. Thank you very much in deep. - Frank
I've post an answer to give better visibility to the answer. - Florent

2 Answers

3
votes

I think this is a better way

class TestConroller implements NgDetachAware {
  void detach() {
    alert("destroy");
  }
}
1
votes

The first parameter of $on must be a pattern.
You must declare it using the r prefix.

$scope.$on(r'$destroy', function() {
  alert("destroy");
});