Angular Dart $scope.$on functionality is not working

那年仲夏 提交于 2020-01-04 02:34:10

问题


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?


回答1:


I think this is a better way

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



回答2:


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

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


来源:https://stackoverflow.com/questions/21403654/angular-dart-scope-on-functionality-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!